public class Demo_Finally {
public static void main(String[] args) {
Demo_Finally df = new Demo_Finally();
//df.foo(1);
df.foo(2);
System.out.println(df.output);//分别运行上面的两行代码,请分析输出结果分别是?
}
public String output = "";
public void foo(int i){
try {
if (i == 1) {
throw new Exception();
}
output += "1";
} catch (Exception e) {
output += "2";
return;
} finally {
output += "3";
}
output += "4";
}
}
|
|