
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
158
Chapter 6
CHAPTER 6
Inheritance
In OOP, inheritance is a formal relationship between two or more classes, wherein
one class borrows (or inherits) the property and method definitions of another class.
In the practical, technical sense, inheritance simply lets one class make use of the
code in another class.
But the term inheritance implies much more than code reuse. Inheritance is as much
an intellectual tool as it is a technical tool. It lets programmers conceptualize a group
of classes in hierarchical terms. In biology, inheritance is a genetic process through
which one living creature passes on traits to another. You are said to have inherited
your mother’s eyes or your father’s nose, even though you don’t look exactly like
either of your parents. In OOP, inheritance has a similar connotation. It lets a class
look and feel in many ways like another class, while adding its own unique features.
We’ll consider the benefits of, and alternatives to, inheritance near the end of this
chapter, under “The Theory of Inheritance.” But first, we need to study the syntax
and general use of inheritance.
A Primer on Inheritance
Let’s consider a very simple, abstract example to get a feel for how inheritance works
(we’ll get into practical applications once we cover the basic syntax). Here’s a class ...