第一种情况是以return的情况显示的
public static void main(String[] args) {
int show = show();
System.out.println(show);
}
public static int show() {
int num = 1;
try {
int result = 5 / 0;
} catch (Exception e) {
return num++;
} finally {
return ++num;
}
}
此时show所显示的答案则为3
当程序进入到try层时,程序异常,则转入到catch层,此时的num还为1,当程序进行到finally层时,此时返回给show()的值则为3
第二种情况是以没有return的情况显示的
第三种情况是以return的位置情况显示的
public static void main(String[] args) {
int show = show();
System.out.println(show);
}
public static int show() {
int num = 1;
try {
int result = 5 / 0;
} catch (Exception e) {
return num++;
} finally {
++num;
}
return num;
}
这种情况的答案则为1