Inheritance and its types

Google+ Pinterest LinkedIn Tumblr +

Inheritance is the concept to inherit the properties of one class to another class. This has also known as class structure again. For example, classes A contains two-member function ads and subtracts and class b contain two another functions multiply and divide. We want to use all these function with one object then we need to use inheritance where class B inherits all the property of class, which is public, but class B. cannot use the private properties of class A. There are following types of inheritance:

1. Single class Inheritance:

When class a gas inherited in class has known as base class and B class is know as derived class. Here only two classes have linked to each other.

2. Multilevel Inheritance:

In this type of inheritance, there are number of level and it has used in that cases where we want to use all properties in number of levels according to the requirement. For example, class A inherited in class b and class b has inherited in class c for class b so on. Where class A is base class c. In another way we can say b is derived class a base class for c and a indirect base class for c is indirect base class for c and c indirect derived class for class A.

3. Multiple Inheritances:

In this type of inheritance, number of classes has inherited in a single class. Where two or more classes are, know as base class and one is derive class.

4. Hierarchical Inheritance:

This type of inheritance helps us to create a baseless for number of classes and those numbers of classes can have further their branches of number of class.

5. Hybrid Inheritance:

In this type of inheritance, we can have mixture of number of inheritances but this can generate an error of using same name function from no of classes, which will bother the compiler to how to use the functions. Therefore, it will generate errors in the program. This has known as ambiguity or duplicity.