Inheritance is the process of creating new classes from the existing class or classes.

Using inheritance, one can create general class that defines traits common to a set of related items. This class can then be inherited (reused) by the other classes by using the properties of the existing ones with the addition of its own unique properties. The old class is referred to as the base class and the new classes, which are inherited from the base class, are called derived classes.

In above figure, the class B contains the three member i.e. Property1, Property2 and Property3. The second class named as D contains four members i.e. Property1, Property2, Property3 and Property4. Out of these, three members (Property1, Property2, Property3) of the class D are same as that of class B, while the one member i.e. Property4 is unique. In the class D, instead of defining all the three members again, one can reuse them from the class B. This feature is known as inheritance which saves time, space, money and increases the reliability and efficiency.

Re: What are the advantages of inheritance? Answer In OOPs, the concept of inheritance # 1 provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have combined features of both the classes.

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.

Sign up to vote on this title
UsefulNot useful