You are on page 1of 8

INHERITANCE IN

C++

FREE DOWNLOAD
CBSE Question Papers, C++ Projects,
C++ Practical Questions & Answers , C++ Tutorial
http://www.cppforschool.com
INHERITANCE IN C++
Inheritance :
– It is the capability of one class to inherit
properties from another class.
• Base Class:
– It is the class whose properties are inherited by
another class. It is also called Super Class.
• Derived Class:
– It is the class that inherit properties from base
class(es).It is also called Sub Class.
FORMS OF INHERITANCE
• Single Inheritance:
– It is the inheritance hierarchy wherein one derived class inherits from
one base class.
• Multiple Inheritance:
– It is the inheritance hierarchy wherein one derived class inherits from
multiple base class(es)
• Hierarchical Inheritance:
– It is the inheritance hierarchy wherein multiple subclasses inherits
from one base class.
• Multilevel Inheritance:
– It is the inheritance hierarchy wherein subclass acts as a base class for
other classes.
• Hybrid Inheritance:
– The inheritance hierarchy that reflects any legal combination of other
four types of inheritance.
FORMS OF INHERITANCE
Visibility Mode
It is the keyword that controls the visibility and availability of inherited
base class members in the derived class. It can be either private or
protected or public.

• Private Inheritance:
– It is the inheritance facilitated by private visibility mode. In private inheritance,
the protected and public members of base class become private members of
the derived class.
• Public Inheritance:
– It is the inheritance facilitated by public visibility mode. In public inheritance,
the protected members of base class become protected members of the
derived class and public members of the base class become public members
of derived class.;
• Protected Inheritance:
– It is the inheritance facilitated by protected visibility mode. In protected
inheritance , the protected and public members of base class become
protected members of the derived class.
Derived class visibility
Base Class
Visibility Public Private Protected
derivation derivation derivation

Private Not Not Not


inherited inherited inherited

Protected Protected Private Protected

Public Public Private Protected


Execution of base class constructor
Method of inheritance Order of execution

class B : public A { }; A(); base constructor


B(); derived constructor

class A : public B, public C B();base (first)


C();base (second)
A();derived constructor

When both derived and base class contains constructors, the


base constructor is executed first and then the constructor in
the derived class is executed. In case of multiple
inheritances, the base classes are constructed in the order in
which they appear in the declaration of the derived class.
FREE DOWNLOAD

CBSE Question Papers


C++ Projects
C++ Practical Questions & Answers
C++ Tutorials

http://www.cppforschool.com

You might also like