From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Leveraging different types of inheritance

Leveraging different types of inheritance - Java Tutorial

From the course: Java Object-Oriented Programming

Leveraging different types of inheritance

- Inheritance can be applied in many different ways, and it's important to choose the right form for your use case. With the employee-salesperson example, we were using single-level inheritance. The employee was the superclass and the salesperson was its only subclass. We can extend this inheritance example by adding additional types of employees. We could add an analyst class. Instead of receiving commission on sales, an analyst receives bonuses each year depending on their performance. An analyst is also an employee, but an analyst is not a salesperson. This type of inheritance is called hierarchical inheritance, where one parent class has many subclasses, and this is also supported in Java. Another type of inheritance we have is multi-level inheritance. A class can inherit from one class, but also be the parent of another class. Let's say we add a person class to the mix an employee is a person, an analyst is a…

Contents