Originally posted by Gamini Sirisena: . . . This is contrary to instance method behaviour.
. . . is there any use for this type of instance variable behaviour?
Instance methods are overridden; instance fields and static members are hidden. We have an FAQ about that.
The use of that type of behaviour is good for people who set exams, or want to make a point. You should probably avoid it like the plague in real-life code. Of course, if all your instance fields have private access, then you will never even know there is a problem with hiding.
Joined: Oct 13, 2005
By the way, it's not called shadowing, but hiding.
Joined: Aug 05, 2008
Agreed, So wouldn't it be nice for the compiler to warn when the same identifier is used for instance variables across a class hierarchy?