Java Reference
In-Depth Information
Figure 1
An Inheritance Diagram
439
440
You may wonder at this point in what way inheritance differs from implementing an
interface. An interface is not a class. It has no state and no behavior. It merely tells
you which methods you should implement. A superclass has state and behavior, and
the subclasses inherit them.
Inheriting from a class differs from implementing an interface: The subclass
inherits behavior and state from the superclass.
One important reason for inheritance is code reuse. By inheriting an existing class,
you do not have to replicate the effort that went into designing and perfecting that
class. For example, when implementing the SavingsAccount class, you can rely
on the withdraw , deposit , and getBalance methods of the BankAccount
class without touching them.
One advantage of inheritance is code reuse.
Search WWH ::




Custom Search