try catch fianlly 笔试题

来源:互联网 发布:怎么比对两列数据 编辑:程序博客网 时间:2024/05/29 12:00

前几天刚转了一个try catch finally return的博客,今天就遇到了这种笔试题,那篇博客看明白了,就可以很轻松的做出来了。

http://blog.csdn.net/zhaoyayua/article/details/38614513

现在将题打出来,共同学习下。

class TryCatchDemo {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);System.out.println(output);}}

运行结果为

13423


0 0