万能百科  > 计算机   > 

[单项选择题] 阅读下面程序 public void test() {  try{   sayHello();   System.out.println

2021-07-20   

[单项选择题] 阅读下面程序 public void test() {  try{   sayHello();   System.out.println("hello");  } catch(ArrayIndexOutOfBoundException e) {   System.out.println("ArrayIndexOutOfBoundException");  } catch(Exception e) {   System.out.println("Exception");  } finally { System.out.println("finally");} } 如果sayHello()方法正常运行,则test()方法的运行结果将是

A.Hello

B.ArraylndexOutOfBondsException

C.Exception  Finally

D.Hello  Finally

正确答案:

D

参考解析:

因为方法sayHello()正常运行,而且语句System.out.println("hello");也没有异常抛出,所以两个catch语句捕获不到异常,因此执行finally子句,输出“finally”。

词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。

标签