一道关于try catch finally返回值的问题

以下这道题,在实际开发中,并不会这么写。

这个是面试官为了考察大家对finally的认识,而苦思冥想出来,我猜的。

    public static void main(String[] args) {    
        System.out.println(finallyTest());
    }
    public static int finallyTest(){
        try {
            int i = 1/0;
        }catch (Exception e){
            return 1;
        }finally {
            return 2;
        }
    }    

结果是多少?你可以先想下。。。。。。。。

答案是:2,因为finally是无论如何都会执行,除非JVM关闭了

原文地址:https://www.cnblogs.com/MJyc/p/13931934.html