【发布时间】:2013-01-27 19:17:38
【问题描述】:
class X extends Exception {
}
class Y extends X {
}
class Z extends Y {
}
public class Test {
static void aMethod() throws Z {
throw new Z();
}
public static void main(String[] args){
int x = 10;
try {
aMethod();
}
catch(X e) {
System.out.println(“Error X”);
}
catch(Y e) {
System.out.println(“Error Y”);
}
}
}
输出是什么?
(A) 两个 catch 都不会捕获异常 块
(B) 它将打印“错误 X”
(C) 它将打印“错误 Y”
【问题讨论】:
-
为什么不编译代码并运行呢?
-
-投票。这不是测验网站。
标签: java exception inheritance