class SomeClass1 {
void method1() { }
public void method2() { }
private void method3() { }
protected void method4() { }
}
class DemoClass{
public static void main(String[] parameters) {
SomeClass1 sc = new SomeClass1();
sc.method1();
sc.method2();
sc.method4();
}
}
Protected methods can only be accessed by classes that inherits the super class. As we can see here DemoClass does not extend SomeClass. But yet, it is able to access the protected method. How is this possible?