面试题之finally中有return语句;
public class Demo {
public static void main(String[] args) {
System.out.println(fun());
}
public static int fun(){
int n = 10;
try{
n = 20;
return n;//1.执行return语句,先将20缓存;2.执行finally;3.返回缓存中的值;
}catch(Exception e){
n = 30;
return n;
}finally{
System.out.println("finally");
n = 40;
return n;
}
}
}
|
|