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的输出值是什么?)

解决方案 »

  1.   

    你试试不就知道了异常时catch和finally都会执行,即使你在catch中return
      

  2.   

    先执行catch中的output+="2";然后是finally,再执行return.
    我没有做出正确结果。因为我忽略了output是个字符串。呵呵
      

  3.   

    134234,finally无论有无异常都要执行,这就是关键
      

  4.   

    答案是13423,我不明白怎么不是134234?
    catch,finally,再执行return,那这return是返回到哪儿呢?
      

  5.   

    return 是直接结束该 过程/函数/方法,
    所以try/catch/final块之后的语句“output+="4";”,将不被执行。
    但final域是在整个过程结束前必须执行的代码片段,所以语句“output+="3";”,依然执行。@.@||~