Please always say where such information comes from. That definition is incorrect, anyway. The correct definition is in the Java® Language Specification (=JLS).
Nyeng Gyang wrote:. . . accessible from (1) All classes that are in the same package as class A and (2) All classes that are subclasses of class A. . . .
It makes protected access hard to understand.
What do you think about this?
I think this is that thread.
Tim Holloway wrote:. . . another thread.
Did you (NG) read the JLS section? Such calls don't constitute part of the object.
. . . you have an instance of "A" named "a" and you're trying to invoke the forbidden method using "a" as the method target.
. . . that does constitute implementing the object.
If the target of the protected method had been "this" or "super", . . .
Beware: it takes a lot of experience to work out whether the site you found provides really good information or a load of old rubbish.
Nyeng Gyang wrote:. . . Googling this topic . . .
I quote the Java™ Tutorials all the time, but I am aware of places where they differ from the official JLS definitions. Remember the JLS is definitive, or take shortcuts for the sake of clarity. The people who wrote the Java™ Tutorials were aware of that. They explain themselves like this:-
The Java™ Tutorials . . .
I think it might be better to call their definition incomplete than wrong.
The Same Tutorials page as before wrote:Many of the examples in the tutorial . . . not recommended for production code.
Campbell Ritchie wrote:I think it might be better to call their definition incomplete than wrong.