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 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 Nested Interface in Java In Java, we can declare interfaces as members of a class or another interface. Such an interface is called a member interface or nested interface. Interfaces declared outside any class can have only public and default (package-private) access specifiers. In Java, nested interfaces (interfaces declar 5 min read Local Inner Class in Java Prerequisites: Nested Classes in Java Local Inner Classes are the inner classes that are defined inside a block. Generally, this block is a method body. Sometimes this block can be a for loop or an if clause. Local Inner classes are not a member of any enclosing classes. They belong to the block the 5 min read Scope of Variables in Java The scope of variables is the part of the program where the variable is accessible. Like C/C++, in Java, all identifiers are lexically (or statically) scoped, i.e., scope of a variable can be determined at compile time and independent of the function call stack. In this article, we will learn about 7 min read Like