Classes in other packages that are subclasses of the declaring class can only access their own inherited protected
members.
public class StoryBook extends Book {
public StoryBook() {
System.out.println(this.variable); // this.variable is visible
}
}
... but not other objects' inherited protected
members.
public class StoryBook extends Book {
public StoryBook() {
System.out.println(this.variable); // this.variable is visible
}
public boolean equals(StoryBook other) {
return this.variable == other.variable; // error: StoryBook.variable is not visible
}
}
Also take a took at this article
Why a protected member of a superclass can't be accessed from a subclass by using a superclass' reference?