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或者缺省(不加)都是可以正常编译。
}
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或者缺省(不加)都是可以正常编译。
}
相关文章推荐
- java-Cannot reduce the visibility of the inherited method from 父类
- java-Cannot reduce the visibility of the inherited method from 父类
- java-Cannot reduce the visibility of the inherited method from 父类
- Java编译错误:Cannot reduce the visibility of the inherited method from <class>
- Cannot reduce the visibility of the inherited method from 编译错误
- Cannot reduce the visibility of the inherited method from Interface解决办法
- Cannot reduce the visibility of the inherited method from
- Android问题:Description Resource Path Location Type Cannot reduce the visibility of the inherited meth
- Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
- Java重写父类使用@Override时出现The method destroy() of type xxx must override a superclass method的问题解决
- The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- Java Compile Error: The code of method is exceeding the 65535 bytes limit
- Cannot assign to 'self' outside of a method in the init family
- Cannot assign to 'self' outside of a method in the init family
- The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- 关于error:Cannot assign to 'self' outside of a method in the init family
- cannot assign to 'self' outside of a method in the init family
- Cannot make a static reference to the non-static method setInAnimation(Animation) from the type View