What Is ‘this’ keyword in java?

The keyword ‘this’ is a reference variable which contains object of current class. When local variable and instance variable name of a class are same, you can differentiate both as follows:
  •              We can refer the local variable directly.
  •       We can refer the instance variable with ‘this’ reference variable.
Example :this.a;
The ‘this’ reference variable is non-static reference variable which can’t be allowed from static context.
The ‘this’ is a reference variable of java.lang.class, ‘this’ variable is declared by java at class loading time.
We can refer the method of current class with ‘this’ reference variable.
Example: this.m1();
Here this.m1() refer to the method of current class


Post a Comment