package xxx.yyy;
public class ParentClass {
protected void doPrint(){
System.out.println("Parent.....");
}
}
package aaa.bbb;
import cathy.inner.ParentClass;
public class Child extends ParentClass {
public void getName(){
System.out.println("Child....");
}
}
A client in package aaa.bbb can not uses new Child().doPrint(). But if child override the then client can use new Child().doPrint().
It seems strange to me because during override we can’t change the access modifier to more restrictive, but is this case inherited method seems private.
Why this is implemented in such a manner ?
Superclass method’s access modifier isprotectedand it states method would be accessible with inclass,packageandsubclass.So it is not accessible in subclass’s package.
when you override that particular method in
subclasswithprotectedaccess modifier then it would accessible asprotectedmethods are accessible under samepackage.