Chapter 5 : Inheritance
In C++, inheritance is a process in which one object acquires all the properties
and behaviours of its parent object automatically. In such way, you can reuse,
extend or modify the attributes and behaviours which are defined in other class.
Types Of Inheritance
o Single inheritance
o Multiple inheritance
o Hierarchical inheritance
o Multilevel inheritance
o Hybrid inheritance
Derived Classes
A Derived class is defined as the class derived from the base class.
The Syntax of Derived class:
class derived_class_name :: visibility-mode base_class_name
{
// body of the derived class.
}
, Visibility modes can be classified into three categories:
o Public: When the member is declared as public, it is accessible to all the
functions of the program.
o Private: When the member is declared as private, it is accessible within
the class only.
o Protected: When the member is declared as protected, it is accessible
within its own class as well as the class immediately derived from it.
Visibility of Inherited Members
Base class visibility Derived class visibility
Public Private Protected
Private Not Inherited Not Inherited Not Inherited
Protected Protected Private Protected
Public Public Private Protected
Single Inheritance
Single inheritance is defined as the inheritance in which a derived class is
inherited from the only one base class.
In C++, inheritance is a process in which one object acquires all the properties
and behaviours of its parent object automatically. In such way, you can reuse,
extend or modify the attributes and behaviours which are defined in other class.
Types Of Inheritance
o Single inheritance
o Multiple inheritance
o Hierarchical inheritance
o Multilevel inheritance
o Hybrid inheritance
Derived Classes
A Derived class is defined as the class derived from the base class.
The Syntax of Derived class:
class derived_class_name :: visibility-mode base_class_name
{
// body of the derived class.
}
, Visibility modes can be classified into three categories:
o Public: When the member is declared as public, it is accessible to all the
functions of the program.
o Private: When the member is declared as private, it is accessible within
the class only.
o Protected: When the member is declared as protected, it is accessible
within its own class as well as the class immediately derived from it.
Visibility of Inherited Members
Base class visibility Derived class visibility
Public Private Protected
Private Not Inherited Not Inherited Not Inherited
Protected Protected Private Protected
Public Public Private Protected
Single Inheritance
Single inheritance is defined as the inheritance in which a derived class is
inherited from the only one base class.