[Todo]很不错的Java面试题类型整理,要看

http://www.importnew.com/21445.html

 

1. 问,以下,会返回什么。

public int func() {
        int ret = 0;
        try{
            throw new Exception();
        }
        catch(Exception e){
            ret = 1;
            return ret;
        }
        finally{
            ret = 2;
            System.out.printf("Set ret to %d\n", ret);
        }
    }

答案:

Set ret to 2
1

因为,虽然finally里面的代码会执行,但是catch里面的return值已经在另外的地方保存起来了。

 

posted @ 2016-10-07 19:19  blcblc  阅读(183)  评论(0编辑  收藏  举报