Java Reference
In-Depth Information
Figure 5
shows the inheritance hierarchy. Exercise P10.2 asks you to add another
class to this hierarchy.
Next, let us determine the behavior of these classes. All bank accounts support the
getBalance
method, which simply reports the current balance. They also support
the
deposit
and
withdraw
methods, although the details of the implementation
differ. For example, a checking account must keep track of the number of transactions
to account for the transaction fees.
444
445
The checking account needs a method
deductFees
to deduct the monthly fees and
to reset the transaction counter. The
deposit
and
withdraw
methods must be
redefined to count the transactions.
Figure 5
Inheritance Hierarchy for Bank Account Classes
The savings account needs a method
addInterest
to add interest.
To summarize: The subclasses support all methods from the superclass, but their
implementations may be modified to match the specialized purposes of the
subclasses. In addition, subclasses are free to introduce additional methods.
S
ELF
C
HECK
4.
What is the purpose of the
JTextComponent
class in
Figure 4