10.4 HYBRID INHERITANCE
Hybrid inheritance is a combination of multiple inheritance and multilevel inheritance. A class is derived from two classes as in multiple inheritance. However, one of the parent classes is not a base class. It is a derived class. This is shown in Figure 10.5.
Let us assume class PlainTicket. It contains information like class (I or II) of travel, distance and fare. Consider a case of class SimpleTicket, a class derived from class PlainTicket. It has additional fields of say date, source and destination stations. Class PaxInfo stores the information of a passenger. Assume that railway issues separate reserved ticket to every passenger. Now class ReservedTicket is derived from PaxInfo and SimleTicket. It is an example of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access