• Concept of defining multiple constructors within the same class by changing the data types of the parameters is known as constructor overloading.
package com.instanceofjavaforus;

public class ConstructorOverloading {

int a,b,c;

ConstructorOverloading(){
    this(1);
}

ConstructorOverloading(int a){
    this(a,2);
}

ConstructorOverloading(int a, int b){
    this(a,b,3);
}

ConstructorOverloading(int a, int b,int c){
this.a=1;
this.b=2;
this.c=3;
System.out.println(a+""+b+""+c);
}
   
public static void main(String args[]){
   
    ConstructorOverloading obj=new ConstructorOverloading();
   
   }
   
}


OutPut:
1 2 3

Instance Of Java

We are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu