CPP

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.



Subscribe us on Youtube

Share This Page on

Questions


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

Can you provide some examples for inheritance.


RichazdEpist | 08-Nov-2018 12:16:27 am

order custom essay http://essayfasthelp.com - write my paper professional custom writing services best essay writing service - thesis template need an essay written


ZatthewNut | 08-Nov-2018 02:34:31 am

help to write a research paper http://essaypromaker.com - custom writing need an essay written write my paper for me - write my nursing paper custom term paper


JaclynRof | 24-Feb-2019 06:42:15 am

How can I get Firefox 3 to stop logging me out everytime I close the browser?


Ask Question