public class MyTest{
public static void main(String args[]) {
System.out.println(test());
}
public static int test() {
try {
System.out.println("try被执行了!");
return 1;
}catch(Exception e) {
System.out.println("catch被执行了!");
e.printStackTrace();
return 2;
}finally {
System.out.println("finally被执行了!");
//return 3;
}
}
}
运行结果:
try被执行了!
finally被执行了!
1
当取消对finally内return 3;注释后,运行结果变为:
try被执行了!
finally被执行了!
3