Java Reference
In-Depth Information
chapter
4
inheritance
A s mentioned in Chapter 3, an important goal of object-oriented pro-
gramming is code reuse. Just as engineers use components over and over in
their designs, programmers should be able to reuse objects rather than repeat-
edly reimplement them. In an object-oriented programming language, the
fundamental mechanism for code reuse is inheritance . Inheritance allows us
to extend the functionality of an object. In other words, we can create new
types with restricted (or extended) properties of the original type, in effect
forming a hierarchy of classes.
Inheritance is more than simply code reuse, however. By using inherit-
ance correctly, it enables the programmer to more easily maintain and update
code, both of which are essential in large commercial applications. Under-
standing of the use of inheritance is essential in order to write significant Java
programs, and it is also used by Java to implement generic methods and
classes.
In this chapter, we will see
General principles of inheritance, including polymorphism
n
How inheritance is implemented in Java
n
How a collection of classes can be derived from a single abstract
class
n
The interface , which is a special kind of a class
n
 
Search WWH ::




Custom Search