Inheritance Hierarchies
- Sets of
classes can form complex inheritance hierarchies
- Example:

Inheritance Hierarchies Example: Swing Hierarchy
- Superclass
JComponent
has methods
getWidth,
getHeight
-
AbstractButton
class has methods to set/get button text and icon

A Simpler Example: Hierarchy of Bank Accounts
- Consider a
bank that offers its customers the following account types
-
Checking account: no interest; small number of free transactions per month,
additional transactions are charged a small fee
-
Savings account: earns interest that compounds monthly
- Inheritance
hierarchy:

- All bank
accounts support the
getBalance
method
- All bank
accounts support the
deposit
and
withdraw
methods, but the implementations differ
- Checking
account needs a method
deductFees;
savings account needs a method
addInterest
What is the
purpose of the
JTextComponent
class in Figure 4?
Answer:
To express the common behavior of text fields and text components.
Which instance
field will we need to add to the
CheckingAccount
class?
Answer:
We need a counter that counts the number of withdrawals and deposits.