Thursday, May 7, 2009

Parameterized Constructor

In constructor can use argument also, the argument values can be passed from the main program. This type of constructors called parameterized constructor.


Example:


header files

class num

{

int a,b;

public:

num(int x, int y) // Parameterized constructor

{

a=x;

b=y;

}

void display()

};

void num::display()

{

cout<<>

cout<<>

}

void main()

{

num obj(1000,5000);

obj.display();

}

Output will be

1000

5000

No comments:

Post a Comment