Start Coding Now

This Keyword in Java - Current Class Instance

Understand the "this" keyword in Java. Refer to the current class instance variable, method, or constructor.

Using 'this' keyword

The this keyword refers to the current object in a method or constructor.

Main Uses:

  • To eliminate confusion between class attributes and parameters with the same name.
  • To invoke current class constructor.
  • To return the current class instance.
  • public class Student {
        String name;

    // 'name' parameter shadows 'name' field Student(String name) { this.name = name; // refers to field } }

    Frequently Asked Questions