Definition and example of parameterized constructor.

PARAMETERIZED CONSTRUCTOR:-

These are the constructors with parameter. Using this Constructor you can provide different values to data members of different objects, by passing the appropriate values as argument.


The constructor with parameters can be used to initialize data members of the object. To create a constructor with parameters you have to specify its parameters in the parentheses as we do to specify parameters of a function.

e.g.


#include<iostream.h>
#include<conio.h>
class number
{
int itemcode,cost;
public:
number(int x,int y)
{
itemcode=x;
cost=y;
}
void display()
{
cout<<"\n code= "<<itemcode;
cout<<"\n cost= "<<cost;
}
};
void main()
{
clrscr();
number n1(192,356);
cout<<"values for first object=";
n1.display();
number n2(546,657);
cout<<"\n value for second object=";
n2.display();
getch();
}




Comments

Popular posts from this blog

How to start windows update service