#include<iostream.h>
#include<conio.h>
class base
{
public:
                int x;
                base()
                {
                                x=10;
                }
};
class derived:public base
{
public:
                int y;
                derived()
                {
                                x=30;
                                y=50;
                }
};
void main()
{
                clrscr();
                base b;
                derived d;
                cout<<"In Base Class X ="<<b.x<<endl;
                b=d;       //Object Slicing
                cout<<"In Base Class 'X' After Object Slicing = "<<b.x<<endl;
                getch();
}

211.PNG

Advertisements