Thursday, May 17, 2018

COPY CONSTRUCTOR,PARAMETERIZED CONSTRUCTOR AND DEFAULT CONSTRUCTOR EXAMPLE RUN TIME IN C++

#include<iostream.h>
#include<conio.h>
class Copy
{
 int x;
 int y;
 static int i;
 public:
     Copy(){}                      //DEFAULT CONSTRUCTOR
     Copy(int p, int q)         //PARAMETERIZED CONSTRUCTOR
     {
      x=p;      y=q;
     }
     Copy(Copy &ob)        //COPY CONSTRUCTOR
     {
      x=ob.x;
      y=ob.y;
     }
     void show()
     {
      cout<<"x and y"<<endl<<x<<"and"<<y<<endl;
     }
};
void main()
{
 Copy ob1(1,2),ob2(2,3),ob3;
 Copy ob(ob1);
 clrscr();
 ob3=ob2;
 ob1.show();
 ob2.show();
 ob3.show();
 ob.show();
 getch();
}

                                                     OUTPUT



No comments:

Post a Comment