-
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 member variables and functions that the base class has and can have additional member functions and/or additional member variables.
-
A base class is also a parent class.
-
A derived class is also a child class.
-
The derived class inherits the member variables and member functions.
-
The definition of an inherited member function can be changed in the definition of a derived class so that it has a meaning in the derived class that is different from what it is in the base class. This is called redefining the inherited member function.
-
A class that is a parent of a parent of a parent of another class is often called an ancestor class.
-
A class is an ancestor of another class that is a class of another class is often called a decendent of that class.
-
A constructor in a base class is not inherited in the derived class, but you can invoke a constructor of the base class with the definition of a derived class constructor.
-
A constructor for a derived class uses a constructor from the base class in a special way. A constructor for the base class intializes all the data inherited from the base class. Thus, a constructor for a derived class begins with an invocation of a constructor for the base class.
-
You should always include an invocation of one of the base class constructors in the initialization section of a derived class constructor.
-
A derived class does not inherit the constructors of its base class. However, when defining a constructor for the derived class, you can and should include a call to a constructor of the base class. If you do not include a call to a constructor of the base class, then the default constructor of the base class will automatically be called when the derived class constructor is called.
-
An accessor function is a function that allows you to access member variables of a class.
-
A mutator function is one that allows you to change member variables of a class.
-
A member variable (or member function) that is private in a base class is not directly accessible outside of the interface and implementation of the base class, not even in a member function definition for a derived class.
-
A private variable can be accessed indirectly via an accessor or mutator member function.
-
If you use the qualifier protected, rather than private or public, before a member variable or member function of a class, then for any class or function other than a derived class, the effect is the same as if the member variable were labeled private; however, in a derived class the variable can be accessed by name.
-
If a member is marked as protected in a base class, then it can be accessed by name in the definitions of all descendent classes, not just in those classes directly derived from the base class.
-
Inheritance provides a tool for code reuse by deriving one class from another by adding features to the derived class.
-
Derived class objects inherit all the members of the base class and may add members.
-
When a member function is redefined in a derived class you must list its function declaration in the class definition even though the function declaration is the same as in the base class.
|
|