Parameterized Constructor

A constructor which has a specific number of parameters is called a parameterized constructor. Why use the parameterized constructor? The parameterized constructor is used to provide different values to distinct objects. However, you can provide the same values also.

Following is the example of parameterized constructor. In this example, we have created the constructor of Student class that have two parameters. We can have any number of parameters in the constructor.


\begin{lstlisting}
//Java Program to demonstrate the use of the parameterized co...
...ay the values of object
s1.display();
s2.display();
}
}
\end{lstlisting}

Output


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