COMPILATION ERROR(It can not be colored with redd...) The reason being that is the protected members can be accessible only through inheritance,the super class reference can not be used to access the protected members(so accessible only through inheritance).To make it work change the class B as
To understand this statement protected members are accessible only through inheritance,look at the codes below from JLS �(6.6.7)
The one other trick which can make you puzzle is the access of inherited protected x,y from a third class which may be or may not be in a package where the subclass is. So the answer is once the subclass outside the package inherits the protected member,that member (as inherited by the subclass) becomes private to any code outside the subclass, with the exception of subclasses of the subclass.
This is also addressed in the Java Language Specification 6.6.7
[I]Consider this example, where the points package declares:
and the threePoint package declares:
which defines a class Point3d. A compile-time error occurs in the method delta here: it cannot access the protected members x and y of its parameter p, because while Point3d (the class in which the references to fields x and y occur) is a subclass of Point (the class in which x and y are declared), it is not involved in the implementation of a Point (the type of the parameter p). The method delta3d can access the protected members of its parameter q, because the class Point3d is a subclass of Point and is involved in the implementation of a Point3d.
The method delta could try to cast (�5.5, �15.16) its parameter to be a Point3d, but this cast would fail, causing an exception, if the class of p at run time were not Point3d.
A compile-time error also occurs in the method warp: it cannot access the protected member z of its parameter a, because while the class Point (the class in which the reference to field z occurs) is involved in the implementation of a Point3d (the type of the parameter a), it is not a subclass of Point3d (the class in which z is declared).[/I]
Once upon a time there were three bears. And they were visted by a golden haired tiny ad: