In Inheritance, the attributes of the base class get carried to the derived class. However, we can assign a base class with the derived class without having the contents of the derived that are uncommon between then, copied to the base class.
Class B
{
public:
int i;
};
{
public:
int i;
};
class D : public B
{
public:
int j;
};
int main()
{
B B1;
D D1;
B1 = D1; //only i is copied to B1
}
{
public:
int j;
};
int main()
{
B B1;
D D1;
B1 = D1; //only i is copied to B1
}

0 Comments:
Post a Comment