When a class has multiple constructors, you often want one constructor to reuse the initialization work performed by another. Java provides the this() constructor call specifically for this purpose.
The name can be confusing at first because Java uses this in several contexts. The important distinction is simple: this refers to the current object, while this() invokes another constructor in the same class.
What Is the this Constructor Call?
The this() constructor call is a special statement used inside a constructor to invoke another constructor of the same class.
class Student {
Student() {
this("Unknown");
}
Student(String name) {
System.out.println(name);
}
}
When new Student() is executed, the no-argument constructor calls this("Unknown"). Java then transfers constructor execution to the constructor that accepts a String.
Why Use this()?
The main reason is code reuse. Without this(), several overloaded constructors may repeat the same initialization statements.
class Employee {
String name;
int age;
String department;
Employee() {
name = "Unknown";
age = 0;
department = "General";
}
Employee(String name) {
this.name = name;
age = 0;
department = "General";
}
}
The initialization of age and department is duplicated. As the class grows, this duplication becomes harder to maintain.
Using this() allows both constructors to share one initialization path.
class Employee {
String name;
int age;
String department;
Employee() {
this("Unknown", 0, "General");
}
Employee(String name) {
this(name, 0, "General");
}
Employee(String name, int age) {
this(name, age, "General");
}
Employee(String name, int age, String department) {
this.name = name;
this.age = age;
this.department = department;
}
}
Now the constructor containing all initialization logic is the final destination of the chain. The other constructors simply provide convenient ways to reach it.
Basic Syntax
this();
This calls another constructor that accepts no arguments.
this(value1, value2);
This calls another constructor whose parameter list matches the supplied arguments.
Simple Example
class Car {
String model;
int year;
Car() {
this("Unknown", 0);
}
Car(String model, int year) {
this.model = model;
this.year = year;
}
}
The no-argument constructor does not initialize model and year itself. Instead, it delegates the work to Car(String model, int year).
Understanding the Execution Flow
Consider this statement:
Car car = new Car();
The execution path is:
new Car()
↓
Car()
↓
this("Unknown", 0)
↓
Car(String model, int year)
↓
Object Initialized
The important point is that the original constructor does not create a second object. The same object is being initialized through another constructor.
this() Does Not Create Another Object
A common beginner misunderstanding is thinking that this() creates another object. It does not.
Student student = new Student();
Only one Student object is created. The this() call simply transfers constructor execution to another constructor belonging to the same object.
Remember: new creates an object. this() calls another constructor to initialize that same object.
this() Must Be the First Statement
Java places a strict restriction on the this() constructor call. It must be the first statement inside the constructor.
class Student {
Student() {
System.out.println("Starting");
this("Rahul");
}
Student(String name) {
System.out.println(name);
}
}
This code is invalid because the this() call appears after another statement.
The correct version is:
class Student {
Student() {
this("Rahul");
}
Student(String name) {
System.out.println(name);
}
}
Important: A constructor cannot perform another statement before this(). The constructor delegation must happen first.
this() and Instance Variable Access
Do not confuse these two forms:
this.name
this(name);
this.name accesses the instance variable named name of the current object. this(name) attempts to call a constructor that accepts one argument.
| Expression | Meaning |
|---|---|
| this | Current object reference |
| this.name | Current object's name field |
| this() | Calls another constructor in the same class |
| this(name) | Calls a matching constructor with one argument |
Constructor Matching
When Java sees this(), it searches for another constructor in the same class whose parameter list can accept the supplied arguments.
class Product {
Product() {
this("Laptop", 65000);
}
Product(String name, double price) {
System.out.println(name);
System.out.println(price);
}
}
The call this("Laptop", 65000) matches the constructor accepting a String and a numeric value compatible with double.
What If No Matching Constructor Exists?
If the arguments supplied to this() do not match any constructor in the same class, the program fails to compile.
class Student {
Student() {
this("Rahul", 20);
}
Student(String name) {
System.out.println(name);
}
}
There is no constructor accepting both a String and an int, so Java cannot resolve the constructor call.
Multi-Level Constructor Chaining
A constructor can call another constructor that calls yet another constructor. This creates a chain of multiple levels.
class Student {
Student() {
this("Unknown");
}
Student(String name) {
this(name, 18);
}
Student(String name, int age) {
this(name, age, "Java");
}
Student(String name, int age, String course) {
System.out.println(name);
System.out.println(age);
System.out.println(course);
}
}
The execution path becomes:
Student()
↓
Student(String)
↓
Student(String, int)
↓
Student(String, int, String)
This pattern is useful when each constructor represents a progressively more detailed way to create the same type of object.
Constructor Chaining Must Eventually Stop
A constructor chain must eventually reach a constructor that performs actual initialization. If constructors continuously call one another, Java cannot complete object initialization.
class Demo {
Demo() {
this(10);
}
Demo(int value) {
this();
}
}
This creates a circular constructor invocation. The no-argument constructor calls the integer constructor, and the integer constructor calls the no-argument constructor again.
Java rejects such circular constructor calls because there is no valid endpoint for the constructor chain.
this() vs super()
Once inheritance enters the picture, you will encounter another special constructor call: super(). The two have related purposes but point to different constructors.
| Feature | this() | super() |
|---|---|---|
| Target | Constructor in the same class | Constructor in the parent class |
| Purpose | Reuse same-class initialization | Initialize the inherited portion of an object |
| Position | Must be the first statement | Must be the first statement |
You will explore super() more deeply when learning inheritance and constructor execution order.
Common Beginner Mistakes
Using this() Outside a Constructor
The this() syntax is specifically a constructor call. It cannot be used as an ordinary method call inside a method.
Writing this() After Other Statements
Student() {
int age = 20;
this("Rahul");
}
This is invalid because the constructor call is not the first statement.
Calling a Nonexistent Constructor
class Car {
Car() {
this("Toyota", 2026);
}
Car(String model) {
}
}
The class does not contain a constructor accepting both a String and an int, so the call cannot be resolved.
Confusing this() with this
Remember that parentheses change the meaning. this refers to the current object, while this() invokes another constructor.
Best Practices
- Use this() when multiple constructors share initialization logic.
- Keep the final constructor in a chain responsible for the actual field initialization.
- Keep constructor chains short and easy to follow.
- Avoid circular constructor invocation.
- Use meaningful constructor overloads rather than creating unnecessary combinations.
- Remember that this() must always be the first statement.
Interview Insight
A common interview question is: Why must this() be the first statement in a constructor? Constructor invocation is part of the object's initialization process, and Java requires the delegated constructor to establish its initialization before the current constructor performs additional statements.
Another frequent question is: Does this() create a new object? No. It invokes another constructor for the same object. The object is created by new, while this() controls which constructor participates in initializing that object.
Quick Revision
| Concept | Key Point |
|---|---|
| this | Refers to the current object |
| this() | Calls another constructor in the same class |
| First Statement | this() must appear first in the constructor |
| Object Creation | new creates the object; this() does not |
| Matching | Arguments must match an available constructor |
| Chaining | Constructors can delegate through multiple levels |
| Circular Calls | Not allowed |
Final Thoughts
The this() constructor call is a small feature with a big impact on clean Java design. It lets overloaded constructors cooperate instead of duplicating initialization code. Once you understand that this() calls another constructor in the same class, must appear first, and works with the same object rather than creating a new one, constructor chaining becomes much easier to design and debug.
