Instance Variable Hiding in Java Last Updated : 31 Jan, 2023 Comments Improve Suggest changes Like Article Like Report 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: Java // Java Program to Illustrate Instance Variable Hiding // Class 1 // Helper class class Test { // Instance variable or member variable private int value = 10; // Method void method() { // This local variable hides instance variable int value = 40; // Note: this keyword refers to the current instance // Printing the value of instance variable System.out.println("Value of Instance variable : " + this.value); // Printing the value of local variable System.out.println("Value of Local variable : " + value); } } // Class 2 // Main class class GFG { // Main driver method public static void main(String args[]) { // Creating object of current instance // inside main() method Test obj1 = new Test(); // Calling method of above class obj1.method(); } } OutputValue of Instance variable : 10 Value of Local variable : 40 Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Instance Variable Hiding in Java T Twinkle Tyagi Improve Article Tags : Java Practice Tags : Java Similar Reads Instance Methods in Java Instance Methods are the group of codes that performs a particular task. Sometimes the program grows in size, and we want to separate the logic of the main method from other methods. A method is a function written inside the class. Since java is an object-oriented programming language, we need to wr 5 min read instanceof Keyword in Java In Java, instanceof is a keyword used for checking if a reference variable contains a given type of object reference or not. Following is a Java program to show different behaviors of instanceof. Henceforth it is known as a comparison operator where the instance is getting compared to type returning 4 min read Using Instance Blocks in Java The instance block can be defined as the name-less method in java inside which we can define logic and they possess certain characteristics as follows. They can be declared inside classes but not inside any method. Instance block logic is common for all the objects. Instance block will be executed o 3 min read Static Variables in Java In Java, when a variable is declared with the static keyword. Then, a single variable is created and shared among all the objects at the class level. Static variables are, essentially, global variables. All instances of the class share the same static variable. These are the main scenarios when we u 3 min read Method Hiding in Java Prerequisite: Overriding in Java If a subclass defines a static method with the same signature as a static method in the superclass, then the method in the subclass hides the one in the superclass. This mechanism happens because the static method is resolved at the compile time. Static method bind d 3 min read Difference Between Object and Instance in Java The object is an instance of a class. A class is like a blueprint or template that defines the properties and behavior of objects. When we create an object we are creating an instance of that class. Object in JavaThe object is an instance of a class. A class is a blueprint or template that describes 3 min read Instance Control Flow in Java This article will explain how Instance Control Flow takes place whenever objects are created. Instance Control Flow In Normal Class Whenever we are executing a java .class file, 1st Static Control Flow will be executed. In the Static Control Flow, if we are creating an object the following sequence 7 min read Private Methods in Java 9 Interfaces Java 9 onwards, you can include private methods in interfaces. Before Java 9 it was not possible. Interfaces till Java 7 In Java SE 7 or earlier versions, an interface can have only two things i.e. Constant variables and Abstract methods. These interface methods MUST be implemented by classes which 4 min read Record Pattern with instanceof in Java 19 In Java, the instanceof operator is used to check whether an object is an instance of a particular class or interface. It returns a boolean value of true if the object is an instance of the specified class or interface, and false otherwise. Example of using instanceof Java public class Example { pub 3 min read Using Static Variables in Java Here we will discuss the static variables in java. Java actually doesnât have the concept of Global variable. To define a Global variable in java, the keyword static is used. The advantage of the static variable is discussed below. Now geeks you must be wondering out what are the advantages of stati 3 min read Like