Here, I am gonna explore coding, Debugging, Error fixing, My articles and other technical posts. So stay tuned.

Use of this keyword in Java | Java This Keyword - Java Programming

No comments

This key word 

Lets create class A and in this class let me define a constructor A which takes a int value in a variable and in the class A there is a Private instance variable. As shown in figure below.

And it also have another show method to display massage. 
So focus on constructor A what we are doing there is we assigning the value of a in the variable x.
so this will work correctly.

But what if we do this.

Now compiler will be confused and it make the instance variable in the constructor to Local Variable.
To over come this confusion we use THIS keyword.

Thank You


No comments :

Post a Comment