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

来源:互联网 发布:客户提醒软件 编辑:程序博客网 时间:2024/06/05 18:25
 

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

 1561人阅读 评论(0) 收藏 举报


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