java-Cannot reduce the visibility of the inherited method from 父类

来源:互联网 发布:万维天文望远镜软件 编辑:程序博客网 时间:2024/05/17 23:58


2014-07-17 10:38 by SchrodingerCat


在Java里面,当A类继承B类,在B类里面重写(或叫覆写/override)A类的方法时,有一个规定,那就是:子类的该方法的权限修饰符范围应该是大于等于父类。

  class A{

    protected method() { }

  }

  class B extends A{

    private method(){ }

    //private是错误的,会出现错误提示:Cannot reduce the visibility of the inherited method from B

    //将protected,public或者缺省(不加)都是可以正常编译。

  }


0 0
原创粉丝点击