类ExampleA继承Exception,类ExampleB继承ExampleA

现有如下的代码-------输出结果是什么?
try { throw new ExampleB("b") } catch(ExampleA e){ System.out.println("ExampleA"); } catch(Exception e){ System.out.println("Exception"); }
答案:
ExampleA
  解析: 根据里氏代换原则
        能够使用父类型的地方一定可以使用子类型,抓取ExampleA类型异常的catch块
            能够抓住try块中抛出的ExampleB类型的异常
  

posted on 2019-03-05 18:15  「28」  阅读(456)  评论(0编辑  收藏  举报

导航