This illustration depicts how inheritance works. It shows that the fields and methods within the Employee class can be used by any class that inherits from it.
The figure shows a diagram of classes and subclasses with the following hierarchy:
- The top level is the class Employee.
A label adds the following information about the hierarchy: "Employee class has two subclasses, PartTimeEmployee and FullTimeEmployee, rather than using attributes of Employee to differentiate between different Employee types. Note: We could have made Employee an interface."
- The second level contains two subclasses derived from the class Employee: class PartTimeEmployee (with the additional field schedule) and class Full Time Employee (with the additional field bonus).
A label adds the following information about the subclasses: "PartTimeEmployees have to track their schedules, while FullTimeEmployees are eligible for bonuses."
- The third level contains two subclasses derived from class FullTimeEmployee: class ExemptEmployee, with the additional method salaryToDate(), and class NonExemptEmployee, with the additional method salaryToDate().
A label adds the following information about these subclasses: "Each FullTimeEmployee is considered "Exempt" if he works for a monthly salary, or "non-exempt" if he works at an hourly rate, Each one computes salaryToDate differently."
End of list.
Both the FullTimeEmployee and PartTimeEmployee class inherits from Employee. This means that both of these classes contain the Employee fields and methods. However, they can also add their own unique fields or methods. For example, the FullTimeEmployee can earn a bonus, so there is a bonus field. The PartTimeEmployee must track their hours, so there is a schedule method.
End of description.