INHERITANCE AND CONSTRUCTOR CALLS in C++ By Shrija Madhu Associate Professor at GIET, Rajahmundry
What is Inheritance When new classes inherit some of the properties and behavior of the existing classes, this technique is known as Inheritance. The existing class or the "parent" of a new class is called a base class and the new class that inherits properties of the base class is called derived class. Inheritance is a technique of code reuse.
Basic Inheritance Parent Child
Types of Inheritance • Single • Hierarchical • Multilevel • Multiple • Hybrid
Single Inheritance A B
Hierarchical Inheritance A CB
Multilevel Inheritance A B C
Multiple Inheritance C BA
Hybrid Inheritance D CB A
Constructor in Base & Derived Class class A { A( ) { } } class B : A { B( ) { } } . . .
Constructor Call class A { A( ) { cout<<“Constructor of A” ; } } class B : A { B( ) { cout<<“Constructor of B” ; } } . . B b;
Output Constructor of A Constructor of B
THE END

Hierarchical inheritance