本帖最后由 邱成 于 2012-9-13 07:26 编辑
class Exceptions{
public String getMsg(){
String msg = "ok";
try {
return msg;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
msg="finally";
System.out.println("进到finally语句块:"+msg);
}
return msg;
}
public static void main(String[] args) {
System.out.println(new Exceptions().getMsg());
}
}
按道理说以上程序会先执行finally语句块,再return try语句块,而执行finally语句块后此时变量msg的值会变成finally,而我们return过后自然应该是打印的
进到finally语句块finally
finally
但是结果却是
进到finally语句块finally
ok
请问这是为什么? |