---
title: "What is this in java?"  
description: "What is this in java?"  
author: "Samuel Fernandes"  
published: 2015-03-27  
updated: 2020-09-19  
canonical: https://www.mindstick.com/interview/2367/what-is-this-in-java  
category: "java"  
tags: ["java"]  
reading_time: 3 minutes  

---

# What is this in java?

**In java, this is a reference variable that refers to the current object.**

1. this keyword can be used to refer current class instance variable.\
2. this() can be used to invoke current class constructor.\
3. this keyword can be used to invoke current class method (implicitly)\
4. this can be passed as an argument in the method call.\
5. this can be passed as argument in the constructor call.\
6. this keyword can also be used to return the current class instance.

\
**Without this:**

```
class Student10{
    int id;
    String name;

    Student10(int id,String name){
    id = id;
    name = name;
    }
    void display(){System.out.println(id+" "+name);}

    public static void main(String args[]){
    Student10 s1 = new Student10(111,"Karan");
    Student10 s2 = new Student10(321,"Aryan");
    s1.display();
    s2.display();
    }
}  
```

\
**Using this:****//example of this keyword**

```
class Student11{
    int id;
    String name;

    Student11(int id,String name){
    this.id = id;
    this.name = name;
    }
    void display(){System.out.println(id+" "+name);}
    public static void main(String args[]){
    Student11 s1 = new Student11(111,"Karan");
    Student11 s2 = new Student11(222,"Aryan");
    s1.display();
    s2.display();
}
}  
```

**\**\

## Answers

### Answer by Anonymous User

**In java, this is a reference variable that refers to the current object.**

1. this keyword can be used to refer current class instance variable.\
2. this() can be used to invoke current class constructor.\
3. this keyword can be used to invoke current class method (implicitly)\
4. this can be passed as an argument in the method call.\
5. this can be passed as argument in the constructor call.\
6. this keyword can also be used to return the current class instance.

\
**Without this:**

```
class Student10{
    int id;
    String name;

    Student10(int id,String name){
    id = id;
    name = name;
    }
    void display(){System.out.println(id+" "+name);}

    public static void main(String args[]){
    Student10 s1 = new Student10(111,"Karan");
    Student10 s2 = new Student10(321,"Aryan");
    s1.display();
    s2.display();
    }
}  
```

\
**Using this:****//example of this keyword**

```
class Student11{
    int id;
    String name;

    Student11(int id,String name){
    this.id = id;
    this.name = name;
    }
    void display(){System.out.println(id+" "+name);}
    public static void main(String args[]){
    Student11 s1 = new Student11(111,"Karan");
    Student11 s2 = new Student11(222,"Aryan");
    s1.display();
    s2.display();
}
}  
```

**\**\


---

Original Source: https://www.mindstick.com/interview/2367/what-is-this-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
