giddee up
giddee up
"Walking on water and building IT Architecture from <br />specification are easy if and only if both are frozen"
SJCP 1.2
from Archana:
...What I tought is , Sub can not see the protectedVar because protectedVar behaves like a privte varible in class Tester(even though they are in the same package) , so cmpiler should give the error when Sub trying to access it
from Yuan:
One thing for sure is that once Tester inherited protectedVar, its SubClass Sub can no longer access protectedVar in its own class. But why Sub can access it in Tester class is really a puzzle.
One thing to ask boyet.
To my understanding of your post, you said the Sub class can access the protected protectedVar, is that true? If it is true, could you please tell me why the Jcompiler doesn't agree? If it is not true, could you explain to me why Sub.protectedVar is a valid statement in the original code.
Does anybody try to run the codes and then make some comments?Please don't just make quote of some book! Use JCompiler to discuss it.
�The reason behind the restriction is this: Each subclass inherits the contract of the superclass and expands that contract in some way. Suppose that one subclass, as part of its expanded contract, places constraints on the values of protected members of the superclass. If a different subclass could access the protected members of objects of the first subclass then it could manipulate them in a way that would break the first subclass�s contract -- and this should not be permissible.�
SCJP2. Please Indent your code using UBB Code
protectedVar=5;
sharana
sharana
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |