CHAPTER OUTLINE
CHAPTER SIX
INHERITANCE
-5 HOURS
6.1 Base and Derived Class
6.2 protected Access Specifier
6.3 Derived Class Declaration
6.4 Member Function Overriding
6.5 Forms of Inheritance: single, multiple, multilevel, hierarchical,
hybrid, multipath
6.6 Multipath Inheritance and Virtual Base Class
6.7 Constructor Invocation in Single and Multiple Inheritances
6.8 Destructor in Single and Multiple Inheritances
Inheritance
Inheritance in Object Oriented Programming can be described
as a process of creating new classes from existing classes.
New classes inherit some of the properties and behavior of the
existing classes.
BASE AND DERIVED CLASS
An existing class that is "parent" of a new class is called a base
class. New class that inherits properties of the base class is
called a child class or derived class.
Inheritance is a technique of code reuse. It also provides
possibility to extend existing classes by creating derived classes.
PROTECTED ACCESS SPECIFIER
The members declared protected are accessible from outside but
only in the classes derived from it.
protected access specifier can be used just like we have used
private and public access specifiers.
Inhertitance is more applicable when there exists is-a
relationship between two classes.
For example: If there are two classes called Fruit and Mango.
There exists is-a relationship between two classes. We can
say Mango is a Fruit. So, Fruit can act as a parent class and
we can derive class Mango from it.
Other examples: Employee is a Person, Leader is a Student,
Maruti is a Car, etc.
The counterpart of inheritance in C++ is composition.
Composition is applicable when there exists has-a
relationship between two classes.
For example: Maruti has-a engine.