I implemented below program where there is a super class called as A and B extends A and class C extends B.
Now i am overiding the method available in respective super classes. My question is why does variable ivar always print the value available in class A. The value for ivar is also defined in class B & class C.
Please let me know if i am missing any concept here.
Here in java when you declare any variable, then if you try to override that variable in the sub class then always the vale of the variable will be hinden and thus the value declared in the super class itself will be seen
Instance variables can not be overridden, they are simply hidden in a subclass when the subclass declares a variable of the same name.
Thus, both variables will still be available and can have different values. The variable you are accessing depends on the reference variable you are using to access the variable.
subject: Overiding class variable through inheritance