java protected method accessibility
- by JavaUser
In the below code the Consumer class can access the protected method of Parent class.How is it possible since there is no relation between Parent and Consumer class.Please explain
class Parent {
public void method1(){
System.out.println("PUBLIC METHOD");
}
private void method2(){
System.out.println("PRIVATE METHOD");
}
protected void method3(){
System.out.println("PROTECTED METHOD");
}
}
public class Consumer {
public static void main(String[] args){
Parent parentObj = new Parent();
parentObj.method1();
//parentObj.method2();
parentObj.method3();
}
}
Thanks