当前位置: 代码迷 >> Java相关 >> 一道关于错误的面试题
  详细解决方案

一道关于错误的面试题

热度:4273   发布时间:2013-02-25 21:45:40.0
一道关于异常的面试题
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
  相关解决方案