“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Kapil Munjal
SCJP 1.4, SCWCD 1.4
The above code is perfectly valid. Forget the details ofSubclass. Just be aware that there is a subclass.In fact whether we use a subclass object / reference as long as it is from the same superclass� file it is visible even if the member is private / package with one exception.
The only case when it won�t be visible would be if the member were private / package but the object and reference both were of the subclass and the member was not visible in the subclass. In that case even if the code is in the super class file it wont compile which makes quite obvious sense.
protected members are accessible to all classes in same package and all classes that inherit even in other packages. Therefore the protected method of the super class should be avialable by inheritence. In that sense the method is inside the derived class.private (and also less restrictive access modifiers) members are accessible to the same class even if from a a different object instance