#include<iostream.h>
class A
{
 public:
   A(int x);
   void display(void);
 protected:
   int a;
};
 A::A(int x)
{
   a=x;
}
 void A::display(void)
{
  cout<<"A::display"<<" a="<<a<<endl; 
}
class B:public A
{
 public:
   B(int x,int y);
   void display(void);
 protected:
   int a;
};
B::B(int x,int y):A(x)
{
  a=y;
}
void B::display(void)
{
  cout<<"B::display"<<" a="<<a<<endl; 
}
class C:public A
{
 public:
   C(int x,int y);
   void display(void);
 protected:
   int a;
};
C::C(int x,int y):A(x)
{
  a=y;
}
void C::display(void)
{
  cout<<"C::display"<<" a="<<a<<endl; 
}
class D:public C
{
 public:
   D(int x,int y,int z);
   void display(void);
 private:
   int a;
 
};
D::D(int x,int y,int z):C(x,y)
{
  a=z;
}
void D::display(void)
{
   cout<<"D::display"<<" a="<<a<<endl;
}
int main()
{
   A s0(0);
   B s1(0,1); 
   C s2(0,2);
   D s3(0,2,3);
   s0.display();  
   s1.display();
   s2.display();
   s3.display();
   A *p[4]={&s0,&s1,&s2,&s3};
   for(int i=0;i<4;i++)
    p[i]->display(); 
   return(0);
}
