Inheritance

 

As the name suggests that it is taking or acquiring some properties from somewhere if we go into its actual definition then INHERITANCE means to get some properties, characteristics or qualities from the predecessor by succession. In this post the inheritance in C++ is discussed.

The definition according to the programming is that the process by which the one class acquire the properties of objects of another class. In other words Inheritance is the mechanism deriving new class from an old one is called inheritance which is also called as derivation. This concept provides the idea of Reusability. This allows user to tailor almost the complete class without any side effects.

The different types of Inheritance are:

1)      Single

2)      Multiple

3)      Hierarchical

4)      Multilevel

5)      Hybrid

The Inheritance adds some more concepts derived class and base class. The syntax of derived class is

Class <derived-class-name> : visibility mode <base-class-name>

{

//body of derived class

};

The visibility mode part is optional here it can be private or public. If its not provided then its private.

Now when the class is publically inherited then the public part of base class becomes the public part of the derived class (in short the public part of base class is inherited to the public part of the derived class) and when the base class is privately inherited then public members of the base class become private members of the derived class.

The private members of the base class are not derived In any of the conditions given above.

Sometimes when we want in our program to inherit the private members of the base class then the C++ provides another visibility modifier, protected. Whenever the member is declared as protected, then that member is accessible by member functions to the class which is derived from that base class.