Information Technology Reference
In-Depth Information
All Classes are Derived From Class object
All
classes, except special class
object
, are derived classes, even if they don't have a class-base
specification. Class
object
is the only one that is not derived, since it is the base of the inherit-
ance hierarchy.
Classes without a class-base specification are implicitly derived directly from class
object
.
Leaving off the class-base specification is just shorthand for specifying that
object
is the base
class. The two forms are completely equivalent.
Figure 7-2 shows both forms of declaration for the same class.
Figure 7-2.
Direct inheritance from object
Other important facts about class derivation are the following:
A class declaration can have only a single class listed in its class-base specification. This
is called
single inheritance
.
Although a class can directly inherit from only a single base class, there is no limit to the
level
of derivation. That is, the class listed as the base class might be derived from
another class, which is derived from another class, and so forth, until you eventually
reach
object
.
Base class
and
derived class
are relative terms. All classes are derived classes, either from
object
or from another class—so generally when we call a class a derived class, we mean that it
is immediately derived from some class other than
object
. Figure 7-3 shows a simple class
hierarchy. After this, I will not show
object
in the figures, since all classes are ultimately derived
from it.
Figure 7-3.
A class hierarchy