What is the use of the 'this' keyword in Java?

The this keyword in Java is a reference to the current object of a class. It is commonly used to access instance variables, invoke methods of the current object, and resolve naming conflicts between instance variables and method parameters.

Key Points

Example

When a constructor parameter has the same name as an instance variable, the this keyword helps differentiate between them.

public class Employee {

    private String name;

    public Employee(String name) {
        this.name = name;
    }

    public void display() {
        System.out.println(this.name);
    }
}

Common Mistakes

Follow-up Questions

Interview Tip

A concise interview answer is

The this keyword is a reference to the current object. It is mainly used to access instance variables, call current class methods or constructors, resolve variable naming conflicts, and refer to the current object within a class.

Last updated: 11 November 2026

Previous question: What are generics in Java?

Next question: What is an enum in Java?

More Core Java - Level I interview questions

All Core Java - Level I questions