i

JAVA Complete Course

Instance Variable Hiding

In Java we can have variable in method with the same name as it is in class. It is allowed by Java syntax. You might have a question, what will happen in that case? Which value will be used? In that case, local variable (variable in method) hides the instance variable. But if we want in method to use value of instance variable, then we need to use keyword this.

The output of this program will be following: