---
description: This constructor overloading in the java tutorial covers the topics like constructor overloading definitions, rules for creating a constructor, chaining with examples
title: Constructor Overloading in Java
image: https://www.guru99.com/images/constructor-overloading-in-java.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Constructor Overloading in Java enables a class to declare multiple constructors that differ by parameter list, giving developers flexible object initialization, cleaner code reuse through this(), and predictable behavior whenever default or custom values are required at instantiation.

* 🏗️ **Definition:** Constructor Overloading in Java allows several constructors in the same class, distinguished by the number, type, or order of parameters.
* 🧩 **Flexibility:** Overloaded constructors initialize objects with different argument sets.
* 🔀 **Chaining:** The this() and super() keywords enable safe constructor chaining.
* ✅ **Defaults:** If a parameterized constructor exists, the default form must be declared.
* 🧪 **Examples:** Code samples demonstrate valid signatures and chaining behavior.

[ Read More ](javascript:void%280%29;) 

![Constructor Overloading in Java](https://www.guru99.com/images/constructor-overloading-in-java.png)

## What is Constructor Overloading in Java?

**Constructor Overloading in Java** is a technique in which a class declares multiple constructors that differ in parameter list. The compiler differentiates these constructors by analyzing the number of parameters and their data types.

Examples of valid constructors for class **Account** are shown below:

Account(int a);
Account (int a,int b);
Account (String a,int b);

## Why Do We Need Constructor Overloading in Java?

Constructor Overloading in Java improves flexibility and code efficiency by allowing several constructors in a class, each with a different parameter list.

* **Flexibility in Object Creation:** Constructor Overloading lets you initialize objects in various ways, depending on the number or type of parameters.
* **Code Reusability:** You can reuse constructor logic by invoking one constructor from another using the **this()** keyword.
* **Improved Readability:** Overloaded constructors make code more intuitive by offering specific options for different initialization needs.
* **Default and Custom Initialization:** Constructor Overloading lets you create both default and custom-initialized objects easily.

## Example: Constructor Overloading in Java

The following example demonstrates Constructor Overloading in Java using a class named **Demo**.

**Step 1)** Type the code in the editor.

class Demo{
      int  value1;
      int  value2;
      /*Demo(){
       value1 = 10;
       value2 = 20;
       System.out.println("Inside 1st Constructor");
     }*/
     Demo(int a){
      value1 = a;
      System.out.println("Inside 2nd Constructor");
    }
    Demo(int a,int b){
    value1 = a;
    value2 = b;
    System.out.println("Inside 3rd Constructor");
   }
   public void display(){
      System.out.println("Value1 === "+value1);
      System.out.println("Value2 === "+value2);
  }
  public static void main(String args[]){
    Demo d1 = new Demo();
    Demo d2 = new Demo(30);
    Demo d3 = new Demo(30,40);
    d1.display();
    d2.display();
    d3.display();
 }
}

**Step 2)** Save, compile, and run the code.

**Step 3)** An error appears. Try to debug the error before proceeding to the next step of Constructor Overloading in Java.

**Step 4)** Every class has a default [Constructor in Java](https://www.guru99.com/java-constructors.html). The default constructor for **class Demo** is **Demo()**. If you do not provide it, the compiler creates it for you and initializes the variables to default values.

However, if you specify a parameterized constructor like **Demo(int a)** and want to use the default **Demo()**, it is mandatory to declare it explicitly.

**Step 5)** Uncomment lines 4-8 of the code, then save, compile, and run the program again to observe the change in behavior.

### RELATED ARTICLES

* [Java BufferedReader: How to Read a File with Example ](https://www.guru99.com/buffered-reader-in-java.html "Java BufferedReader: How to Read a File with Example")
* [Scala Tutorial ](https://www.guru99.com/scala-tutorial.html "Scala Tutorial")
* [Selection Sorting in Java Program with Example ](https://www.guru99.com/selection-sorting-java.html "Selection Sorting in Java Program with Example")
* [80 Java Collections Interview Questions and Answers (2026) ](https://www.guru99.com/java-collections-interview-questions-answers.html "80 Java Collections Interview Questions and Answers (2026)")

## Constructor Chaining in Java

Consider a scenario where a base class is extended by a child. Whenever an object of the child class is created, the constructor of the parent class is invoked first. This is called **Constructor chaining**.

**Example:** To understand constructor chaining with Constructor Overloading in Java

**Step 1)** Copy the following code into the editor.

class Demo{
   int  value1;
   int  value2;
    Demo(){
      value1 = 1;
      value2 = 2;
      System.out.println("Inside 1st Parent Constructor");
   }
   Demo(int a){
      value1 = a;
      System.out.println("Inside 2nd Parent Constructor");
   }
  public void display(){
     System.out.println("Value1 === "+value1);
     System.out.println("Value2 === "+value2);
  }
  public static void main(String args[]){
     DemoChild d1 = new DemoChild();
     d1.display();
  }
}
class DemoChild extends Demo{
    int value3;
    int value4;
    DemoChild(){
    //super(5);
     value3 = 3;
     value4 = 4;
    System.out.println("Inside the Constructor of Child");
    }
    public void display(){
      System.out.println("Value1 === "+value1);
      System.out.println("Value2 === "+value2);
      System.out.println("Value1 === "+value3);
      System.out.println("Value2 === "+value4);
   }
}

**Step 2)** Run the code. Owing to constructor chaining, when the object of child class **DemoChild** is created, the constructor **Demo()** of the parent class is invoked first and the constructor **DemoChild()** of the child runs next.

**Expected Output:**

Inside 1st Parent Constructor
Inside the Constructor of Child
Value1 === 1
Value2 === 2
Value1 === 3
Value2 === 4

**Step 3)** You may observe that the parent constructor **Demo()** runs by default. To call the overloaded constructor **Demo(int a)** instead, use the keyword **“super”**.

**Syntax:**

super();
--or--
super(parameter list);

**Example:** If your parent constructor is like **Demo(String Name, int a)**, you will specify **super(“Java”,5)**. If used, the keyword **super** needs to be the first line of code in the constructor of the child class.

**Step 4)** Uncomment line 26 and run the code. Observe the output.

**Output:**

Inside 2nd Parent Constructor
Inside the Constructor of Child
Value1 === 5
Value2 === 0
Value1 === 3
Value2 === 4

This code is editable. Click Run to Compile + Execute   

![](https://www.guru99.com/Customization/CodeEditorFiles/Common/ajax-loader.gif)

## FAQs

🏗️ What is a Constructor in Java?

A Constructor is a special method used to initialize a newly created object, called just after memory allocation. If no user-defined constructor is provided, the compiler initializes member variables to default values such as 0 for numeric types and null for references.

📏 What are the rules for creating a Java Constructor?

A Java constructor must share the same name as its class and must not declare any return type, not even void. Constructor Overloading in Java is achieved by varying the number, type, or order of parameters across multiple constructor declarations within the same class.

🔗 What is Constructor Chaining?

Constructor Chaining occurs when a child class constructor invokes a parent class constructor, either implicitly or explicitly using super(). It works alongside Constructor Overloading in Java to ensure inherited fields are initialized correctly before subclass-specific logic runs during object creation.

🔀 How is Constructor Overloading different from Method Overloading?

Constructor Overloading defines multiple constructors that initialize objects in different ways, while Method Overloading defines multiple methods that perform related operations with different inputs. Constructors run during object creation with new, whereas overloaded methods are invoked explicitly on existing objects or classes.

🤖 Can AI generate overloaded constructors automatically?

Yes, AI coding assistants can generate Constructor Overloading in Java from natural language prompts or class diagrams. They produce constructor signatures, delegate logic with this(), and add Javadoc comments, which accelerates boilerplate creation while still requiring developer review for correctness and project conventions.

🧠 How can AI help refactor constructor patterns?

AI tools can analyze existing classes and recommend refactoring of Constructor Overloading in Java by merging redundant constructors, introducing builder patterns, or extracting initialization helpers. They highlight ambiguous overloads, suggest parameter renaming, and align constructor design with patterns such as immutability and dependency injection.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter](https://www.guru99.com/images/footer-email-avatar-imges-1.png) Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/constructor-overloading-in-java.png","url":"https://www.guru99.com/images/constructor-overloading-in-java.png","width":"700","height":"250","caption":"Constructor Overloading in Java","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/constructor-overloading-in-java.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/java-tutorials","name":"Java Tutorials"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/constructor-overloading-in-java.html","name":"Constructor Overloading in Java"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/constructor-overloading-in-java.html#webpage","url":"https://www.guru99.com/constructor-overloading-in-java.html","name":"Constructor Overloading in Java","dateModified":"2026-06-24T19:01:47+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/constructor-overloading-in-java.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/constructor-overloading-in-java.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/james","name":"James Hartman","description":"I am James Hartman, a seasoned professional in Oracle Certified Java Professional tutorials, specializing in crafting comprehensive guides to help you excel in your Java certification journey.","url":"https://www.guru99.com/author/james","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","url":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","caption":"James Hartman","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Java Tutorials","headline":"Constructor Overloading in Java","description":"This constructor overloading in the java tutorial covers the topics like constructor overloading definitions, rules for creating a constructor, chaining with examples","keywords":"java","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/james","name":"James Hartman"},"dateModified":"2026-06-24T19:01:47+05:30","image":{"@id":"https://www.guru99.com/images/constructor-overloading-in-java.png"},"copyrightYear":"2026","name":"Constructor Overloading in Java","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is a Constructor in Java?","acceptedAnswer":{"@type":"Answer","text":"A Constructor is a special method used to initialize a newly created object, called just after memory allocation. If no user-defined constructor is provided, the compiler initializes member variables to default values such as 0 for numeric types and null for references."}},{"@type":"Question","name":"What are the rules for creating a Java Constructor?","acceptedAnswer":{"@type":"Answer","text":"A Java constructor must share the same name as its class and must not declare any return type, not even void. Constructor Overloading in Java is achieved by varying the number, type, or order of parameters across multiple constructor declarations within the same class."}},{"@type":"Question","name":"What is Constructor Chaining?","acceptedAnswer":{"@type":"Answer","text":"Constructor Chaining occurs when a child class constructor invokes a parent class constructor, either implicitly or explicitly using super(). It works alongside Constructor Overloading in Java to ensure inherited fields are initialized correctly before subclass-specific logic runs during object creation."}},{"@type":"Question","name":"How is Constructor Overloading different from Method Overloading?","acceptedAnswer":{"@type":"Answer","text":"Constructor Overloading defines multiple constructors that initialize objects in different ways, while Method Overloading defines multiple methods that perform related operations with different inputs. Constructors run during object creation with new, whereas overloaded methods are invoked explicitly on existing objects or classes."}},{"@type":"Question","name":"Can AI generate overloaded constructors automatically?","acceptedAnswer":{"@type":"Answer","text":"Yes, AI coding assistants can generate Constructor Overloading in Java from natural language prompts or class diagrams. They produce constructor signatures, delegate logic with this(), and add Javadoc comments, which accelerates boilerplate creation while still requiring developer review for correctness and project conventions."}},{"@type":"Question","name":"How can AI help refactor constructor patterns?","acceptedAnswer":{"@type":"Answer","text":"AI tools can analyze existing classes and recommend refactoring of Constructor Overloading in Java by merging redundant constructors, introducing builder patterns, or extracting initialization helpers. They highlight ambiguous overloads, suggest parameter renaming, and align constructor design with patterns such as immutability and dependency injection."}}]}],"@id":"https://www.guru99.com/constructor-overloading-in-java.html#schema-1120737","isPartOf":{"@id":"https://www.guru99.com/constructor-overloading-in-java.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/constructor-overloading-in-java.html#webpage"}}]}
```
