Lecture 11, 12 - Chapter 9 - Inheritance
Lecture 11, 12 - Chapter 9 - Inheritance
Object-Oriented Programming:
Inheritance
Java™ How to Program, 9/e
package java.lang)
Every class in Java directly or indirectly extends (or “inherits
from”) Object.
Java supports only single inheritance, in which each
class is derived from exactly one direct superclass.
Desired,
but illegal,
situation
15
9.2 Superclasses and Subclasses
(Cont.)
Not every class relationship is an inheritance
relationship.
Has-a relationship
Create classes by composition of existing classes.
Example: Given the classes Employee, BirthDate and
TelephoneNumber, it’s improper to say that an Employee
is a BirthDate or that an Employee is a
TelephoneNumber.
However, an Employee has a BirthDate, and an
Employee has a TelephoneNumber.
sales
Base-salaried commission employees receive a base
potential problems.
The subclass object can set an inherited variable’s
engineering practices.
Class CommissionEmployee declares instance
image formats.
JLabel method setText changes the text the label
displays.