From the course: Java Object-Oriented Programming

Unlock the full course today

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

What is inheritance?

What is inheritance?

- [Instructor] Another key object-oriented principle is Inheritance. Inheritance allows us to create class hierarchies where classes inherit properties and behaviors from other classes. With Inheritance, we have two main players, the subclass and the superclass. We call the class that inherits the properties the subclass or child class. The class that's being inherited from is called the superclass or the parent class. In Inheritance, the child class inherits properties from the parent class, or the subclass inherits properties from the superclass. For example, let's say we have an employee class. The class has name, ID, and salary attributes. Now what if we wanted to represent a salesperson in code? A salesperson would also have a name, ID, and salary, but they might also have a commission percentage or other attributes and behaviors. While we could create a fresh new class for the salesperson with name, ID, and salary attributes, we could also use Inheritance to help reduce code in…

Contents