Parameterized Constructor – java

Is part of Constructor:

What is Parameterized Constructor ?
– Constructor that have the parameter.

Why we need Parameterized constructor ?
– To provide different valuse to distinct objects.

Lets look the example:

package javaconstructor;

// My Parameterized Constructor

public class parameterized_constructor {
String name;

parameterized_constructor(int i, String n){
id =i;
name = n;}

void display(){
System.out.println(id+” “+name);}

publicstaticvoid main(String args[]){// To provide different values to distinct objects.

parameterized_constructor s1 =new parameterized_constructor(101,”raju”);
parameterized_constructor s2 =new parameterized_constructor(102,”ahmad”);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s