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. Following is the example of Constructor Overloading.


\begin{lstlisting}
//Java program to overload constructors
class Student5 {
i...
...ent5(222,''Aryan'',25);
s1.display();
s2.display();
}
}
\end{lstlisting}

Output


\begin{lstlisting}
111 Karan 0
222 Aryan 25
\end{lstlisting}