首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

一道关于错误的面试题

2012-06-11 
一道关于异常的面试题public class yichang {public static void main(String[] args){System.out.println

一道关于异常的面试题
public class yichang {
public static void main(String[] args){
System.out.println(testyichang());
}

private static int testyichang() {
// TODO Auto-generated method stub
try{
return 1;
}catch(Exception e){
return 2;
}finally{
System.out.print("123#");
return 3;
}
}
}
输出结果是123#3,为什么不执行try或catch里面的语句?

[解决办法]
try中的return执行了的,只不过finally中的return 3覆盖了返回值。

请参阅:
http://topic.csdn.net/u/20120607/07/9d3a5948-ca38-4eb9-a4f8-63400b34e13a.html

热点排行