Instance Variable Hiding in java program – “this keyword”

What is Instance variable Hiding in Java Program?

– When our instance variables (class variables) are same with parameter variables that time have to specified our class variables so that time we use “this keyword” in our program.

– At that time we hide instance variable in “this keyword”. So we can call instance variable hiding.



Let’s see example on instance variable hiding in java program – “This keyword”

class ThisKeyword


            int No;                                                              // instance variable

            String name,address;


            void setData(int No,String name,String address)          // Parameter Variable


                        this.No = No;

               = name;

                        this.address = address;


            void displayData()


            System.out.println(“No = ” + this.No + “\nName = ” + name + “\nAddress = ” + address);



class clEx4


            public static void main(String args[])


                        ThisKeyword obj = new ThisKeyword();          // Object


                        obj.setData(101,”Ami Watsone”,”Gree Valley”);






No = 101

Name = Ami Watsone

Address = Green Valley


In this example, we can see instance variables No, name and address are same as setData(int No,String name,String address) parameters variable.

This keyword” cover the instance variable and indicate as class variables.


Video available on YouTube.



If you have query about this blog, you can directly post comment or subscribe on website.


576total visits,1visits today


Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.