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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
What is inheritance?2m 41s
-
(Locked)
Leveraging different types of inheritance2m 49s
-
(Locked)
Using inheritance to reduce code duplication4m 51s
-
(Locked)
Discovering inheritance in foundational Java classes3m 18s
-
(Locked)
Challenge: Reduce redundant code with inheritance1m 51s
-
(Locked)
Solution: Reduce redundant code with inheritance4m 37s
-
(Locked)
-
-
-