Constructor Overloading in Java

In this tutorial, we will learn about Constructor Overloading in Java. A constructor can be over overload just like Method Overloading. In java, we can create more than one Constructor in class. The only rule is all the constructors should have different arguments(In the number of arguments or type of arguments).

Rules to perform Constructor Overloading in Java:

  • Constructor name should same.
  • Arguments must be different(Number or arguments or type of arguments)

Example Program:

public class OverloadExample{
  public OverloadExample(){
    System.out.println("This is default Constructor");
  public OverloadExample(int x){
    System.out.println("This is parameterized Constructor");
  public static void main(String args[]){
    new OverloadExample();
    new OverloadExample(10);

As you can see in the above example when we are writing constructor to make the object of the class in the main function. It is automatically invoking to particular constructor according to the actual argument we are passing.

Spread the love