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 I remove the access modifier "public" from Line1/Line 2, the compiler
complains that I am applying weaker access privileges for the methods
"eat()" obtained from the ursus interface.
Does it mean that all methods obtained from interfaces should be only
"public" on the classes which implement that interface ?
No comments:
Post a Comment