如何证明一个继承的类的构建器不能捕捉它的基础类的构建器的违例啊??
请教~~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();
}
}