It is mentioned that a subclass outside the package can not access member which has protected modifier using a reference to an instance of superclass..
But below code gives the different behaviour.
package
fruit;
public class parent{
protected static void p1( ){
System.out.println("Parent class");
}
}
import fruit.parent;
public class child extends parent{
public static void main (
String ARGS[]){
child c = new child();
c.p1();
}
}
class child complies and output : "parent class"
Please explain why it is not giving the compile error.
Thanks in advance.