Why can’t my subclass access a protected variable of its superclass, when it’s in a different package?

It works, but only you the children tries to access it own variable, not variable of other instance ( even if it belongs to the same inheritance tree ). See this sample code to understand it better: //in Parent.java package parentpackage; public class Parent { protected String parentVariable = “whatever”;// define protected variable } // … Read more

Call protected method from a subclass of another instance of different packages

Don’t know the rationale, but JLS confirms this in 6.6.2. Details on protected Access (emphasis mine): A protected member or constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object. So: package P2; public class P2 { … Read more

Protected access modifier in Java

The webpage @MadProgrammer linked gives a decent explanation: “The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.” This means the protected member must be accessed directly through either the class it is defined in … Read more