Hi,
Following class Base1 is in package base1p
package base1p;
public class Base1{
protected void amethod()
{
System.out.println("amethod1");
}
}
Following class Base2 is in default package.
import base1p.Base1;
public class Base2 extends base1p.Base1
{
public static void main(
String argv[])
{
Base1 b = new Base1();
b.amethod();
}
}
This gives a compiler error saying "Can't access protected method amethod in class base1p.Base1. base1p.Base1 is not a subclass of the current class. b.amethod();"
But if both classes are given in the same source file, it prints "amethod1".
Any idea why it gives this error as protected should be accessible from another package?.