我有如下三个接口(interface)
interface CFL extends PowerSaver, LightingDevice{
void showLifeTime();
void getBrand();
}
interface PowerSaver {
void showEcoRate();
}
interface LightingDevice {
void doLight();
}
然后我创建一个名为 Philips 的抽象类来实现 CFL
public abstract class Philips implements CFL{
void showLifeTime(){}; // Compiler says Cannot reduce the visibility of the inherited method from CFL.
void showEcoRate(){}; // Compiler says Cannot reduce the visibility of the inherited method from CFL.
}
我的问题是为什么它说我无法降低从 CFL 继承的方法的可见性。而我还没有减少它?
最佳答案
接口(interface)实现必须是public
。
要了解错误,请参阅 spec :
Every method declaration in the body of an interface is implicitly
public
.
因此,您实际上是在重写(或者在本例中是实现)public
方法。
关于java - 在抽象类中实现时降低 java 接口(interface)的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8584802/