单选题:阅读以下Java程序,其编译运行结果是?
阅读以下Java程序,其编译运行结果是?
public class Test {
public int div(int a, int b) {
try {
return a / b;
}catch(Exception e){
System.out.println("Exception");
}catch(NullPointerException e){
System.out.println("ArithmeticException");
}catch (ArithmeticException e) {
System.out.println("ArithmeticException");
} finally {
System.out.println("finally");
}
return 0;
}
public static void main(String[] args) {
Test demo = new Test();
System.out.println("商是:" + demo.div(9, 0));
}
}
A.Exception<br>
finally<br>
商是:0
B.ArithmeticException<br>
finally<br>
商是:0
C.finally<br>
商是:0
D.编译报错
答案:D
public class Test {
public int div(int a, int b) {
try {
return a / b;
}catch(Exception e){
System.out.println("Exception");
}catch(NullPointerException e){
System.out.println("ArithmeticException");
}catch (ArithmeticException e) {
System.out.println("ArithmeticException");
} finally {
System.out.println("finally");
}
return 0;
}
public static void main(String[] args) {
Test demo = new Test();
System.out.println("商是:" + demo.div(9, 0));
}
}
A.Exception<br>
finally<br>
商是:0
B.ArithmeticException<br>
finally<br>
商是:0
C.finally<br>
商是:0
D.编译报错
答案:D