Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL : Inheritance Fundamentals. 2 CRITICAL SKILL : Base Class Access Control 7 CRITICAL SKILL : Using protected Members. 9 CRITICAL SKILL : Calling Base Class Constructors . 14 CRITICAL SKILL : Creating a Multilevel Hierarchy . 22 CRITICAL SKILL : Inheriting Multiple Base Classes 25 CRITICAL SKILL : When Constructor and Destructor Functions Are Executed. | Module 10 Inheritance Virtual Functions and Polymorphism Table of Contents CRITICAL SKILL Inheritance CRITICAL SKILL Base Class Access CRITICAL SKILL Using protected CRITICAL SKILL Calling Base Class CRITICAL SKILL Creating a Multilevel CRITICAL SKILL Inheriting Multiple Base CRITICAL SKILL When Constructor and Destructor Functions Are CRITICAL SKILL Pointers to Derived CRITICAL SKILL Virtual Functions and CRITICAL SKILL Pure Virtual Functions and Abstract This module discusses three features of C that directly relate to object-oriented programming inheritance virtual functions and polymorphism. Inheritance is the feature that allows one class to inherit the characteristics of another. Using inheritance you can create a general class that defines traits common to a set of related items. This class can then be inherited by other more specific classes each adding those things that are unique to it. Built on the foundation of inheritance is the virtual function. The virtual function supports polymorphism the one interface multiple methods philosophy of object-oriented programming. 1 C A Beginner s Guide by Herbert Schildt CRITICAL SKILL Inheritance Fundamentals In the language of C a class that is inherited is called a base class. The class that does the inheriting is called a derived class. Therefore a derived class is a specialized version of a base class. A derived class inherits all of the members defined by the base class and adds its own unique elements. C implements inheritance by allowing one class to incorporate another class into its declaration. This is done by specifying a base class when a derived class is declared. Let s begin with a short example that illustrates several of the key features of inheritance. The following program creates a base class called TwoDShape that stores