Protected data and methods are accessible to all the classes within the same package and to all the subclasses of any package. Now if this holds true, why the following prog. failed to compile.
The protected members in the superclass are accesseble to the subclasses only through inheritance in another words you can not use the super class reference in the subclass to access the protected members. The above code will choke at
Basically Protected members are accessible by subclass of another package only by inheritance and not by Reference of its superclass...
so here in first case you are using the super class reference to access its variable which is not permitted whereas in second case you are accessing by the subclass reference which actually has its copy of variable in it...so its allowed...its nothing but telling the compiler "am accessing my own variable and not the superclass variable"
hope you got it..
Harish Paravasthu
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
Free, earth friendly heat - from the CodeRanch trailboss