Constructor Overloading in Java2 Jul 2025 | 5 min read 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 Advantages of Constructor Overloading
Disadvantages of Constructor Overloading
Java Constructor Overloading MCQs1. Which of the following best describes constructor overloading?
Answer: B) Explanation: Constructor overloading involves having multiple constructors with different parameter lists. 2. What will happen if a class has only parameterized constructors and no default constructor?
Answer: B) Explanation: Without a default constructor, creating an object without parameters will cause a compilation error. 3. What is the purpose of using this() in a constructor?
Answer: B) Explanation: this() is used to call another constructor in the same class. 4. Can a constructor be synchronized in Java?
Answer: B) Explanation: Constructors cannot be synchronized because it doesn't make sense to synchronize object creation. 5. Which of the following is true about constructor overloading?
Answer: B) Explanation: Overloaded constructors can have different access modifiers. Next TopicPackage-java-time-does-not-exist |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India