CPP
Inheritance in Cpp
INHERITANCE
INTRODUCTION
- Inheritance is the feature by which objects of one class acquire the properties of objects of another class .
- It is the mechanism of deriving a new class from an old one.
- It supports the concept of hierarchical classification.
- The concept of inheritance provides the idea of reusability .
- This means we can add additional features to an existing class without modifying it .
- This is possible by deriving a new class from an existing one .
- The new derived class will have the features of the existing class as well as its own unique features .
- Inheritance allows the implementation of data members or member functions that were previously defined.
ADVANTAGES
- The application can be built over previously available module.
- Extension of any application is rapid .
- The codes that were previously tested can be used as the foundation for newer modules.
- Time and cost of development is controlled.
Syntax
class derived_class_name : visibility_mode class base_class_name
{
//members of derived class
private:
………
protected:
………
public:
………
};
- base_class_name – The name of the base/parent/super class from which the new class will inherit its features
- derived_class_name – The name of the derived/child/sub class which acquires the properties of the old existing class
- visibility_mode -
- Determines the mode of derivation of features into the child class
- Can be private, protected or public
- The default visibility mode is private(optional, if not written, it is considered private)
TYPES OF INHERITANCE
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
CPP