您的位置:首页 > 编程语言 > Java开发

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

2014-08-20 22:12 567 查看

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或者缺省(不加)都是可以正常编译。

  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐