The Java Language Specification says
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.
What that means is that if you're writing a subclass outside the package of the original class, each object can call the superclass's protected methods on itself, but not on other objects.
In your example, because s
is a different object from this
, you can't call s.fun()
. But the object would be able to call the fun
method on itself - with this.fun()
or just fun()
.