Statistics
The Highest Post







Statistics
Count 94
Avg 21.00
Min 21
Max 21
Angualr Top questions

Details



Peter Agyekum What is Constructor Overloading? In Java, a constructor is just like a method but without return type. It can also be overloaded like Java methods. Constructor overloading in Java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types. class Student5{ int id; String name; int age; //creating two argument constructor Student5(int i,String n){ id = i; name = n; } //creating three argument constructor Student5(int i,String n,int a){ id = i; name = n; age=a; } void display(){System.out.println(id+" "+name+" "+age);} public static void main(String args[]){ Student5 s1 = new Student5(111,"Karan"); Student5 s2 = new Student5(222,"Aryan",25); s1.display(); s2.display(); }
Related Topics