CPP Concepts of Inheritance

Concepts of Inheritance

  • Inheritance is one of the key feature of object-oriented programming.
  • it allows user to create a new class(derived class) from a existing class(base class).
  • The derived class inherits all feature from a base class and it can have additional features of its own.

Types of Inheritance:

C++, we have 5 different types of Inheritance. Namely,
  1. Single Inheritance
  2. Multiple Inheritance
  3. Hierarchical Inheritance
  4. Multilevel Inheritance
  5. Hybrid Inheritance (also known as Virtual Inheritance)

Access Control and Inheritance:

  • A derived class can access all the non-private members of its base class.
  • Thus base-class members that should not be accessible to the member functions of derived classes should be declared private in the base class.
  • Following table shows different access types according to who can access them in the following way:
Access public protected private
Same class yes yes yes
Derived classes yes yes no
Outside classes yes no no

When deriving a class from a base class, the base class may be inherited through public, protected or private inheritance

Public Inheritance:

  • When deriving a class from a public base class,public members of the base class become public members of the derived class and protected members of the base class becomeprotected members of the derived class.
  • A base class's privatemembers are never accessible directly from a derived class, but can be accessed through calls to the public and protected members of the base class.

Protected Inheritance:

  • When deriving from a protected base class,public and protected members of the base class become protectedmembers of the derived class.

Private Inheritance:

  • When deriving from a private base class,public and protected members of the base class become privatemembers of the derived class.

Share This Page on:


Heli | 07-Nov-2016 01:52:55 pm

Can you provide some examples for inheritance.

Claudiaquini | 17-Nov-2017 08:51:49 am

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil 3.0": captcha solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another subtypes of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? You can find a lot of introducing videos about XEvil in YouTube. Good luck ;) P.S. XEvil 4.0. recognize ReCaptcha2 too !

Ask Question