Inheritance in c++
- Inheritance allows new classes to be constructed on the basis of existing classes. The new derived class “inherits” the data and methods of the so-called base class. But you can add more characteristics and functionality to the new class.
- Inheritance is the process by which one object can acquire the properties of another object.
- This is important because it supports the concept of hierarchical classification.
- Without the use of hierarchies, each object would have to explicitly define all of its characteristics. Using inheritance, an object need only define those qualities that make it unique within its class.
- It can inherit its general attributes from its parent. Thus, it is the inheritance mechanism that makes it possible for one object to be a specific instance of a more general case.
Uses of Inheritance
- Inheritance is a design tool that allows developers to take an existing class and produce a new class that provides enhanced behavior or different behavior
- The enhanced or new behavior does not come at the expense of existing code; that is, when using inheritance programmers do not touch any source code in the base class.
- Also, developers can leverage existing code (in the base class) without duplicating it in the derived classes.
Types of Inheritance
- Single Inheritance.
- Multilevel Inheritance.
- Multiple Inheritance.
- Heirarchical Inheritance.
- Hybrid Inheritance.
- Multipath Inheritance.