Multi-level Inheritance
Inheritance can have multiple levels. That is, a base class can have derived classes, each of which can have derived classes, and so on. These classes constitute what is known as an inheritance hierarchy (or inheritance tree). All the rules that apply for single-level inheritance also apply for multiple level inheritance. You can extend your example with the Person, Employee, and Customer to add two more classes to the hierarchy: SalesEmployee and Manager. These are both derived from the Employee class. The sales employees have a base salary (represented by the base class Employee m_salary) and a monthly bonus, calculated based on a percentage of the salary. The managers have a salary (like all employees) and a managerial ...
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