SCJP6
I am the one who knows that I don't know anything.
Abhijeet
Abhijeet Pathak wrote:Dude it's a rule "You cannot access protected variables from subclass by creating an object of base class in the subclass."
SCJP6
I am the one who knows that I don't know anything.
Abhijeet
can not override static method/variables . but can be accessed by sub class
Mo Jay wrote:you can inherit a static variable from the parent class and you can override it by changing its value. Give it a try to see.
SCJP6
A sub class can, of course, still change the value contained in the static.
Nitish Bangera wrote:Abhijeet you are right that protected variables cannot be accesed from a different class.
my question is when the variable in class A was declares as protected static. it was accessed using the class A's reference variable a.x. It worked properly. I am asking why does it work
When the variable is just protected then yes abhijeet's answer is right
but when it is declared as protected static then it can be accessed.
SCJP6
I am the one who knows that I don't know anything.
Abhijeet
SCJP6
Nitish wrote:When the variable is just protected then yes abhijeet's answer is right
Jason wrote: No it is not. See above.
I am the one who knows that I don't know anything.
Abhijeet
Nitish Bangera wrote:Jason its quiet clear now.... Thanks and don't be angry ok... This seems to be a simple topic of statics but it had stuck on my mind that why it does work this way and not that way. Well now its clear Thanks for the reply.
SCJP6
Abhijeet Pathak wrote:Explain yourself.
SCJP6
Experience and talent are independent of age
Himanshu Kansal wrote:[code]This wont compile if "x" is not static in A. Hence static has a role to play.
And I clearly assume A and B are in 2 different packages.
SCJP6
Jason Irwin wrote:
Abhijeet Pathak wrote:Explain yourself.
Can you follow why this works?
I am the one who knows that I don't know anything.
Abhijeet
Experience and talent are independent of age
Nitish Bangera wrote:Static members are one for the class.. but are they inherited when an other extends a class with static members???please help me on this issue...
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |