Thursday, April 19, 2012

"Cannot reduce the visibility of the inherited method from ..." - inteface are implicitly public

http://stackoverflow.com/questions/8584802/reducing-visibility-of-the-java-interface-when-implementing-it-in-an-abstract-cl

interface CFL extends PowerSaver, LightingDevice{
    void showLifeTime();
    void getBrand();
}

interface PowerSaver {
    void showEcoRate();
}

interface LightingDevice {
    void doLight();
}
 
 
public abstract class Philips implements CFL{
    void showLifeTime(){}; // ! => Cannot reduce the visibility of the inherited method from CFL.
    void showEcoRate(){};  // ! => Cannot reduce the visibility of the inherited method from CFL.
}
 
 
Interface implementations must be public.
To understand the error, see the spec:
Every method declaration in the body of an interface is implicitly public.
Therefore, you're actually overriding (or, in this case, implementing) public methods.
 

No comments:

Post a Comment