如何证明一个继承的类的构建器不能捕捉它的基础类的构建器的违例啊??

seraphmk2 2002-02-27 01:28:49
请教~~thinking in java中第10章的作业第10题Demonstrate that a derived-class constructor cannot catch exceptions thrown by its base-class constructor.
该如何编程来证明这个问题啊?
下面是我编的...但super()只能位于构建器的第一句啊,所以不知道该如何改才对~~
class A{
A(int i)throws Exception{
throw new Exception();
}
}

class C extends A{
C(int i) throws Exception{
try{super(11);
}catch(Exception e){
e.printStackTrace() ;
}
}
}


public class B {
public static void main(String[] args) throws Exception{
new C();

}
}
...全文
35 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimjxr 2002-03-03
  • 打赏
  • 举报
回复
只让你演示,不一定要编程。“super()只能位于构建器的第一句啊”这就是答案。
seraphmk2 2002-03-03
  • 打赏
  • 举报
回复
up.....
seraphmk2 2002-02-28
  • 打赏
  • 举报
回复
up~~

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧