Overriding member variables in Java ( Variable Hiding)

When you make a variable of the same name in a subclass, that’s called hiding. The resulting subclass will now actually have both properties. You can access the one from the superclass with super.var or ((SuperClass)this).var. The variables don’t even have to be of the same type; they are just two variables sharing a name, much like two overloaded methods.

Leave a Comment