CoreJava/exp9/FinallyDemo2.java
2024-05-09 09:10:51 +08:00

29 lines
745 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 如下所示代码中如果catch里面有return语句请问finally的代码还会执行吗?
// 如果会请问是在return前还是return后。请使用debug方法查看程序中的变量a的取值是多少。
// 如果将最后一名return a;语句移到finally中那么又会是什么情况。
package exp9;
public class FinallyDemo2 {
public static void main(String[] args) {
System.out.println(getInt());
}
public static int getInt() {
int a = 10;
try {
System.out.println("try");
System.out.println(a / 0);
a = 20;
} catch (ArithmeticException e) {
System.out.println("catch");
a = 30;
return a;
} finally {
System.out.println("finial");
a = 40;
//return a;
}
return a;
}
}