Constructor Overloading
public class Overloading {
/* Constructor overloading is the re definition of a number of constructors with
difference in number of arguments or type of arguments. */
Overloading() {
System.out.println("Inside constructor without any parameters");
}
Overloading(int a) {
System.out.println("Inside constructor accepting integer parameter " + a);
}
Overloading(String a) {
System.out.println("Inside constructor accepting String parameter " + a);
}
public static void main(String[] args) {
Overloading over1 = new Overloading();
Overloading over2 = new Overloading(100);
Overloading over3 = new Overloading("HELLO WORLD..!!");
}
}
Output:
Inside constructor without any parameters
Inside constructor accepting integer parameter 100
Inside constructor accepting String parameter HELLO WORLD..!!