java - Access Modifiers on methods obtained from Interfaces -


   interface ursus {    public void eat();  }  class grizzly implements ursus {   public void eat() //line 1  {    system.out.println("grizzly  eats salmon ");  }  }  class polar implements ursus {   public void eat() //line 2  {    system.out.println("polar eats seals ");  }  }  class ursus_test {   public static void main(string args[])  {    grizzly g = new grizzly();   polar p = new polar();   p.eat();   g.eat();   }  } 

when remove access modifier "public" line1/line 2, compiler complains applying weaker access privileges methods "eat()" obtained ursus interface.

does mean methods obtained interfaces should "public" on classes implement interface ?

as per docs

the public access specifier in interface indicates interface can used class in package. if not specify interface public, interface accessible classes defined in same package interface.

all methods declared in interface implicitly public, public modifier can omitted. if explicitly try add other access modifier compiler complaint.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -