Pages

Sunday, 28 June 2015

All Classes Are Derived from Class object

All Classes Are Derived from Class object

All classes, except the special class object, are derived classes, even if they don’t have a class-base specification. Class object is the only class that is not derived, since it is the base of the inheritance 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.
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.
Lets go back to our employee class in previous example, the actual class hierarchy is shown in following figure:

0 comments:

Post a Comment