Java Reference
In-Depth Information
7
Inheritance
Like mother, like daughter.
COMMON SAYING
Introduction
Object-oriented programming (OOP) is a popular and powerful programming philoso-
phy. One of the main techniques of OOP is known as
means
that a very general form of a class can be defined and compiled. Later, more specialized
versions of that class may be defined by starting with the already defined class and adding
more specialized instance variables and methods. The specialized classes are said to
inheritance.
Inheritance
the methods and instance variables of the previously defined general class. In this
chapter we cover inheritance in general and more specifically how it is realized in Java.
inherit
Prerequisites
This chapter does not use any material on arrays from Chapter 6. It does require
Chapters 1 through 5 with the exception that most of the chapter does not require
Section 5.4 on packages and
. The subsection “Protected and Package Access”
is the only part of this chapter that requires anything from Section 5.4 and it requires
only the material on packages and not any material on
javadoc
. The subsection “Pro-
tected and Package Access” can be omitted without any loss of continuity in reading
this chapter.
javadoc
7.1
Inheritance Basics
If there is anything that we wish to change in the child, we should
first examine it and see whether it is not something that could better
be changed in ourselves.
CARL GUSTAV JUNG,
The Integration of the Personality
Inheritance is the process by which a new class—known as a
derived class
—is created
from another class, called the
. A derived class automatically has all the
instance variables and all the methods that the base class has, and can have additional
methods and/or additional instance variables.
base class
Search WWH ::




Custom Search