DEV Community

KIRUBAGARAN .K
KIRUBAGARAN .K

Posted on

This in java

Definition of this in Java

In Java this is a reference variable that refers to the current object or can be said this in Java is a keyword that refers to the current object instance.

  • Call current class methods and fields
  • To pass an instance of the current class as a parameter
  • To differentiate between the local and instance variables

Call current class methods and fields

  • this helps to access fields (instance variables) of the current object.
  • It also helps to call methods of the same class explicitly

Methods to Use this in Java

  • Using "this" keyword to refer to current class instance variables.
  • Using this() to invoke the current class constructor
  • Using 'this' keyword to return the current class instance
  • Using 'this' keyword as the method parameter
  • Using 'this' keyword to invoke the current class method
  • Using 'this' keyword as an argument in the constructor call

Top comments (0)