package cn.bdqn;
public class TestFinally {
public static void main(String[] args) {
int i=method1();
System.out.println(i);
}
public static int method1(){
try{
System.out.println(10/0);
return 1;
}catch(Exception e){
e.printStackTrace();
/*暂时保存在内存中,不返回,等finally代码块执行完再返回,
若是finally中有return 值,该值为最终值,覆盖return 3*/
return 3;
}finally{
System.out.println("大家好");
return 2;
}
}
}
try/catch/finally中分别有return,执行顺序是什么?
猜你喜欢
转载自blog.csdn.net/Java_stud/article/details/82317779
今日推荐
周排行