- Concept of defining multiple constructors within the same class by changing the data types of the parameters is known as constructor overloading.
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
No comments