This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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?