Assume that we have the following class definition:
Now, we find that altough class X is useful, it does not fully represent the attributes of a type of program objects. Assume that we need to represent a new data member, and call that m.
We have “two” ways to approach this problem. Let us consider the following definitions:
In both cases, class Y and class Z has the extra data member m. However, class Y inherits all the members of class X, whereas class Z has a class X member.