日期:2014-05-20  浏览次数:20839 次

一道关于异常的面试题
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