10.2 Inheritance Design
We say that an “is a” relationship exists between a subclass and a superclass; that is, a subclass object “is a” superclass object. For example, we could define a student class hierarchy with a Student superclass and derive a GraduateStudent subclass. A graduate student “is a” student, but actually a special type of student. We could also define an employee class hierarchy with an Employee superclass and derive Faculty and Staff subclasses, because faculty and staff are both special types of employees.
To design classes for inheritance, our superclass should define fields and methods that will be common to all classes in the hierarchy. Each subclass will provide specialization by adding methods and fields. Where appropriate, ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.