Here is the example code of Java Constructor Overloading.
***Code***
public class ConstructorEG {
String name;
Integer number;
ConstructorEG(){
System.out.println("Default Constructor called");
}
ConstructorEG(String defaultValue){
System.out.println("Parameterized Constructor for name called");
name = defaultValue;
}
ConstructorEG(Integer number){
System.out.println("Parameterized Constructor for number called");
this.number = number;
}
public static void main(String[] args) {
ConstructorEG object = new ConstructorEG("custom value");
System.out.println(object.name);
ConstructorEG object2 = new ConstructorEG(123);
System.out.println(object2.number);
}
}
***Output***
Constructor called
custom value