10.9 RELATIONSHIPS

After studying inheritance in detail, we are in a position to study two cases where two classes are related to each other. It is tempting to call it inheritance relationships. However, it must be noted that this term is not defined in literature. The two relations are termed as “is–a” and “has–a” relationships.

 

images

 

Figure 10.10 Multilevel inheritance with multiple paths

10.9.1 is–a Relationship

Consider a simple example. We may have a base class as vehicle. The classes car and motorcycle may be derived from it. Now the relationship between derived class and base class can best be described as “is–a” relationship. A car is ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.