Constructor Overloading in JavaLast 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
Example of Constructor OverloadingConsider the following Java program, which utilises different constructors within the class. ExampleCompile and RunOutput: 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 OverloadingHowever, 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. ExampleCompile and RunOutput: 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 Next TopicPackage-java-time-does-not-exist |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India