Sunday, February 27, 2011

Virtual Class

#include<iostream.h>
#include<conio.h>
 class base
 {
 public:
 int x;
 base()
 {
       cout<<"\n Setting the value of X";
        x=10;
       getch();
 }
 };

class drived1:virtual public base
 {
    public:
    drived1()
    {
        cout<<"\ Drived 1";
        getch();
     }
 };

class drived2:virtual public base
 {
   public:
   drived2()
   {
    cout<<"\n Drived 2";
           getch();
    }
 };

class drived3:public drived1, public drived2
 {
 public:
 void show()
 {
 cout<<"\n Value of X is "<<x;
 }
 };

 void main()
 {
 clrscr();
 drived3 obj;
 obj.show();
 getch();
 }

No comments:

Post a Comment