Constructor Overloading in Java

In java Constructor can also be overloaded like methods overloading. We can create as many constructors with different arguments.Constructor can be of default without any parameter or parameterized constructor.

While we define parameterized constructor compiler will not define default constructor at compile time.If no any default constructor found then compiler generates an error while creating objects using default constructor.

Here I am taking example to overload constructors for Product class.

package com.startwithjava;
public class Product {
private int id;
private String name;
private double price;
public Product(){ = id; = name;
this.price = 0;
public Product(int id, String name, double price) {
super(); = id; = name;
this.price = price;
public Product(int id,String name){ = id; = name;
this.price = 0;
public void display(){


public class ConstructorOverloading {

public static void main(String args[]){

//Default Constructor
System.out.println("Using Default Constructor");
Product p = new Product();

//Parameterized Constructor

System.out.println("\nUsing Parameterized Constructor");

Product p2 = new Product(100,"A",5000);



Using Default Constructor
Id:0    Name:null    Price0.0

Using Parameterized Constructor
Id:100    Name:A    Price5000.0


Leave a Reply