29 lines
745 B
Java
29 lines
745 B
Java
|
// 如下所示代码中,如果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;
|
|||
|
}
|
|||
|
}
|