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

这个是面试官为了考察大家对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关闭了

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-01-18
  • 2021-10-20
  • 2021-07-14
  • 2021-12-04
猜你喜欢
  • 2021-08-06
  • 2022-12-23
  • 2022-02-18
  • 2021-09-28
  • 2021-05-17
  • 2021-09-27
  • 2022-12-23
相关资源
相似解决方案