PROGRAM TO IMPLEMENT CONCEPT OF CONSTRUCTORS

/*PROGRAM TO IMPLEMENT CONCEPT OF CONSTRUCTORS*/

#include<conio.h>

#include<iostream.h>

class abc

{

int a,b;

public:

abc()

{

a=b=0;

}

abc(int x,int y)

{

a=x;

b=y;

}

abc(abc &m)

{

a=m.a;

b=m.b;

}

void display()

{

cout<<“a= “<<a<<” b= “<<b<<endl;

}

};

void main()

{

clrscr();

abc a1;

abc a2(4,5);

abc a3=a2;

cout<<“Display function for default constructor is executed:\n”;

a1.display();

cout<<“Display function for parameterized constructor is executed:\n”;

a2.display();

cout<<“Display function for copy constructor is executed:\n”;

a3.display();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *