-
Notifications
You must be signed in to change notification settings - Fork 0
Overloaded Constructors:
rahul Kumar edited this page Aug 7, 2020
·
1 revision
Within a class we can declare multiple constructors and all these constructors having the same name but a different types of arguments. Hence all these constructors are considered as overloaded constructors. Hence overloading concept applicable for constructors.
package src.constructor;
public class OverloadedConstructors {
OverloadedConstructors(){
this(10);
System.out.print("no arg constructor");
}
OverloadedConstructors(int x){
this(10.5);
System.out.print("int arg constructor");
}
OverloadedConstructors(double x){
System.out.print("double arg constructor");
}
public static void main(String[] args){
OverloadedConstructors o = new OverloadedConstructors();
OverloadedConstructors o1 = new OverloadedConstructors(10);
OverloadedConstructors o2 = new OverloadedConstructors(10.5);
OverloadedConstructors o3 = new OverloadedConstructors(10l);
}
}