Java Reference
In-Depth Information
7
Inheritance
Like mother, like daughter.
COMMON SAYING
Introduction
Object-oriented programming (OOP) is a popular and powerful programming
philosophy. One of the main techniques of OOP is known as inheritance . Inheritance
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 inherit 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.
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 javadoc . In this chapter, the subsection “Protected and
Package Access” is the only section that requires any knowledge from Section 5.4, and
it requires only the material on packages, and not the material on javadoc . If you
omit the subsection “Protected and Package Access,” you will not suffer any loss of
continuity in reading this chapter.
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 base class . 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.
 
 
Search WWH ::




Custom Search