PROGRAM FOR DEFAULT,COPY AND PARAMETERISED CONSTRUCTOR

//program for default,parameterised and copy constructor
#include<iostream.h>
#include<conio.h>
class sample
{
  int id;
  public:
   sample(){}
   sample(int a)
   {
     id=a;
   }
   sample(sample &a)
   {
    id=a.id;
   }
   void display()
   {
     cout<<id<<endl;
   }
};
void main()
{
  sample a(100);
  sample b(a);
  sample c=a;
  sample d;
  clrscr();
  d=a;
  a.display();
  b.display();
  c.display();
  d.display();
  getch();
}

Comments

Popular Posts