java 类,为什么输出结果会是这样?
来源:百度知道 编辑:UC知道 时间:2024/07/08 13:59:28
50、分析下面的Java程序段输出结果为( )。
public class yy {
public static void main(String[] args) throws Exception {
try {
throw new Exception( );
}catch(Exception e){
System.out.println("Caught in main( )");
}
System.out.println("nothing");
}
}
A、Caught in main( )
B、Caught in main( )
nothing
C、nothing
D、没有任何输出
解答:A
我不知道为什么输出结果会是这样,这里有什么知误点我不知道吧
哪位可以给我说说呢?
public class yy {
public static void main(String[] args) throws Exception {
try {
throw new Exception( );
}catch(Exception e){
System.out.println("Caught in main( )");
}
System.out.println("nothing");
}
}
A、Caught in main( )
B、Caught in main( )
nothing
C、nothing
D、没有任何输出
解答:A
我不知道为什么输出结果会是这样,这里有什么知误点我不知道吧
哪位可以给我说说呢?
楼主的答案不对啦.
在里面人工抛一个异常,
被catch捕获,
程序进入catch块,
打印Caught in main( ),
当然如果有finally的块的话,
会再执行finally的语句,
然后程序执行下面的语句,
再打印nothing。
所以答案是B,已验证过。
在try里抛出了个异常throw new Exception( );
被catch接住,然后执行了System.out.println("Caught in main( )");
如此而已
答案应该是B:Caught in main()
noting
答案错了
输出
Caught in main( )
nothing
答案错了 应该是B
我帮你运行了一下,答案是
Caught in main()
nothing