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
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking