Difference Between this and this() in Java Last Updated : 12 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In Java, both this and this() are completely different from each other. this keyword is used to refer to the current object, i.e. through which the method is called.this() is used to call one constructor from the other of the same class.The below table shows the point-to-point difference between both this keyword and this(). thisthis()this keyword is used with the objects only. this() is used with constructors only. It refers to the current object. It refers to the constructor of the same class whose parameters matches with the parameters passed to this(parameters). Dot(.) operator is used to access the members. For example, this.variableName; No Dot(.) operator is used. Only the matching parameters are passed. It is used to differentiate between the local variable and the instance variable in the method. It is used to refer to the constructor belonging to the same class. See the code below, which describes the utilization of this keyword. Java import java.io.*; public class Student { private String name; private int age; // Note that in the Constructor below "this keyword" is // used to differentiate between the local variable and // the instance variable. public Student(String name, int age) { // Assigns the value of local name variable // to the name(instance variable). this.name = name; // Assigns the value of local Age variable // to the Age(instance variable). this.age = age; } public void show() { System.out.println("Name = " + this.name); System.out.println("Age = " + this.age); } public static void main(String[] args) { // Creating new instance of Student Class Student student = new Student("Geeks", 20); student.show(); } } OutputName = Geeks Age = 20 Now take a look at the code below which describes the use of this(). Java import java.io.*; public class Student { private String name; private int age; // Constructor 1 with String as parameter. public Student(String name) { // This line of code calls the second constructor. this(20); System.out.println("Name of Student : " + name); } // Constructor 2 with int in parameter. public Student(int age) { System.out.println("Age of student = " + age); } // Constructor 3 with no parameters. public Student() { // This line calls the first constructor. this("Geeks"); } public static void main(String[] args) { // This calls the third constructor. Student student = new Student(); } } OutputAge of student = 20 Name of Student : Geeks Please note that this() should always be the first executable statement in the constructor. Otherwise, the program will give compile time error. Comment More infoAdvertise with us Next Article Difference Between Void and Non Void Methods in Java A ankitsinghrajput Follow Improve Article Tags : Java Difference Between Practice Tags : Java Similar Reads Difference Between Class.this and this in Java In java, Class.this and this might refer to the same or different objects depending upon the usage. this this is a reference variable that refers to the current object. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity. Class.this Cla 3 min read Difference between super() and this() in java super and this keyword super() as well as this() keyword both are used to make constructor calls. super() is used to call Base class's constructor(i.e, Parent's class) while this() is used to call the current class's constructor. Let us see both of them in detail: super() Keyword super() is used to 7 min read Difference Between wait() and notify() in Java The wait() and notify() are methods of the Object class. They were introduced to part ways with polling, which is the process of repeatedly checking for a condition to be fulfilled. Polling wastes CPU resources considerably, hence it is not preferred. wait() Methodwait() method is a part of java.lan 7 min read What is the difference between self and $this ? The keyword self is used to refer to the current class itself within the scope of that class only whereas, $this is used to refer to the member variables and function for a particular instance of a class. PHP self operator: The self operator represents the current class and thus is used to access cl 2 min read Difference Between Void and Non Void Methods in Java The method in Java or Methods of Java is a collection of statements that perform some specific task and return the result to the caller. Every method has a return type that can be differentiated between void and non-void. In this article, we will learn about void and non-void methods. Void Methods i 2 min read Difference between static and non-static method in Java A static method is a method that belongs to a class, but it does not belong to an instance of that class and this method can be called without the instance or object of that class. Every method in java defaults to a non-static method without static keyword preceding it. Non-static methods can access 6 min read Like