public class Test{
public static String output="";
public static void foo(int i){
try{
if(i==1){
throw new Exception();
}
output+="1";
}
catch(Exception e){
output+="2";
return;
}
finally{
output+="3";
}
output+="4";
}
public static void main(String[] args){
foo(0);
foo(1);
24;
}
{
what is the value of output at line 24?(24行output的输出值是什么?)
public static String output="";
public static void foo(int i){
try{
if(i==1){
throw new Exception();
}
output+="1";
}
catch(Exception e){
output+="2";
return;
}
finally{
output+="3";
}
output+="4";
}
public static void main(String[] args){
foo(0);
foo(1);
24;
}
{
what is the value of output at line 24?(24行output的输出值是什么?)
我没有做出正确结果。因为我忽略了output是个字符串。呵呵
catch,finally,再执行return,那这return是返回到哪儿呢?
所以try/catch/final块之后的语句“output+="4";”,将不被执行。
但final域是在整个过程结束前必须执行的代码片段,所以语句“output+="3";”,依然执行。@.@||~