Java |异常处理|问题7

预测以下程序的输出。

null

class Test
{
String str = "a" ;
void A()
{
try
{
str += "b" ;
B();
}
catch (Exception e)
{
str += "c" ;
}
}
void B() throws Exception
{
try
{
str += "d" ;
C();
}
catch (Exception e)
{
throw new Exception();
}
finally
{
str += "e" ;
}
str += "f" ;
}
void C() throws Exception
{
throw new Exception();
}
void display()
{
System.out.println(str);
}
public static void main(String[] args)
{
Test object = new Test();
object.A();
object.display();
}
}


(A) 阿布德夫 (B) 阿卜杜勒 (C) 阿布德夫 答复: (B) 说明: “throw”关键字用于显式抛出异常。 最后,即使发生异常,也始终执行块。 对方法C()的调用引发异常。因此,控件进入方法B()的catch块,该块再次抛出异常。因此,控件进入方法A()的catch块。 这个问题的小测验 如果你在上面的帖子中发现任何错误,请在下面发表评论

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享