VOOZH about

URL: https://www.geeksforgeeks.org/java/instance-variable-hiding-in-java/

⇱ Instance Variable Hiding in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Instance Variable Hiding in Java

Last Updated : 23 Jul, 2025

One should have a strong understanding of this keyword in inheritance in Java to be familiar with the concept. Instance variable hiding refers to a state when instance variables of the same name are present in superclass and subclass. Now if we try to access using subclass object then instance variable of subclass hides instance variable of superclass irrespective of its return types.

In Java, if there is a local variable in a method with the same name as the instance variable, then the local variable hides the instance variable. If we want to reflect the change made over to the instance variable, this can be achieved with the help of this reference.

Example:


Output
Value of Instance variable : 10
Value of Local variable : 40

Time Complexity: O(1)

Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: