类 Example A 继承 Exception,类 ExampleB 继承 Example A
有如下代码片断:
try{
throw new ExampleB("b");
} catch(ExampleA e){
System.out.printfln("ExampleA");
} catch(Exception e){
System.out.printfln("Exception");
}
输出的内容应该是:
A.ExampleA
B.Exception
C.b
D.无
参考解答
输出为A。 因为catch语句后声明的异常类型可以捕获该异常类型或该异常类型的子类型,因此catch(ExampleA e)可以捕获ExampleA和ExampleA的子类异常。