Constructor Overloading in Java

Last Updated : 15 Jan 2026

In Java, we can overload constructors like methods. The constructor overloading allows a class to have multiple constructors with different parameter lists.

Important Points to Remember

  • A class can have multiple constructors.
  • Each overloaded constructor must have a different parameter list. The difference may lie in the number of parameters, the types of parameters, and the order of parameters.
  • Overloaded constructor does not have any return type, not even void type.
  • Overloading gives you the flexibility to create an object using various sets of starting values, or to use default values when some parameters are not specified automatically. It's a handy way to make your code more adaptable and user-friendly.
  • Overloaded constructors can invoke other constructors within the same class using the this() keyword, which helps in reducing code duplication.

Example of Constructor Overloading

Consider the following Java program, which utilises different constructors within the class.

Example

Compile and Run

Output:

This is a default constructor
Default Constructor values: 
Student ID: 0
Student Name: null
Parameterized Constructor values: 
Student ID: 10
Student Name: David

Explanation

In the above example, the Main class constructor is overloaded with two different constructors: the default constructor and a parameterized constructor.

Here, we need to understand the purpose of constructor overloading. Sometimes, we need to use multiple constructors to initialize the different values of the class.

We must also note that the Java compiler invokes a default constructor when no constructor is specified in the class. However, the default constructor is not invoked if we have used any constructor in the class, whether it is default or parameterized. In this case, the Java compiler throws an exception stating that the constructor is undefined.

Consider the following example, which contains the error since the Colleges object cannot be created using the default constructor now, since it does not contain one.

Use of this() in Constructor Overloading

However, we can use this keyword inside the constructor to invoke the other constructor of the same class.

Consider the following example to understand the use of this keyword in constructor overloading.

Example

Compile and Run

Output:

Printing Student Information: 
Name: John
Id: 101
Contact No.: 9899234455
College Name: 9899234455
Passing Year: 2018

When Does Java Constructor Overloading Get Necessary?

In Java, a class can have more than one constructor specified with the same name but distinct parameters. Depending on the inputs provided, it enables the construction of objects with various sets of starting states, promoting flexibility in object initialisation.

Constructor overloading is necessary when a class needs to initialize different objects in different ways. For example, a class representing a geometric shape may contain constructors that take multiple parameters, including starting coordinates, colours, and dimensions. The overloading of constructors allows the class to handle different initialization conditions without requiring distinct method names.

To read more Difference Between Constructor Overloading and Method Overloading in Java