0

Inheritance in C++ Programming

C Programming

 

 

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.

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.

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.

 

 

Base Class Visibility Derived class visibility
Public derivation Private derivation Protected derivation
Private Not inherited Not inherited Not inherited
Protected Protected Private Protected
Public Public Private Protected

 

Containership:When a class contains objects of other class types as its members, it is called containership. It is also called containment,composition, aggregation.

Execution of base class constructor

Method of inheritace 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.

 

Overriding of method(function) in inheritance

We may face a problem in multiple inheritance, when a function with the same name appears in more than one base class. Compiler shows ambiguous error when derived class inherited by these classes uses this function.

We can solve this problem, by defining a named instance within the derived class, using the class resolution operator with the function as below :

 

 

Virtual Base Class : 

Multipath inheritance may lead to duplication of inherited members from a grandparent base class. This may be avoided by making the common base class a virtual base class. When a class is made a virtual base class, C++ takes necessary care to see that only one copy of that class is inherited.

 



You Need "Inheritance in C++ Programming" ???


"Inheritance in C++ Programming" (Source Code / Report / PPT) Totally belong to CodingTalks Team and We always ready to Share our Stuff with our users. If you are Very Much Interested on This Topic Then you must Leave a Comment what Exactly you Looking For Or Send us Email to get Full Information.

Coding Talks
Team

Filed in: C/C ++ Tags: , , , , , , , , ,

Get Updates

Share This Post

Related Posts

Leave a Reply

Submit Comment

© 2017 CodingTalks. All rights reserved.

Warning: filemtime(): stat failed for /home/codingtalks/public_html/wp-content/plugins/floating-social-share-bar//js/waypoints.min.js in /home/codingtalks/public_html/wp-content/plugins/floating-social-share-bar/floatingshare.php on line 213