Inheritance

When a new class is derived from another class is called inheritance. the old class is called base class and new class is called derived class. the main advantage of inheritance is reusability of the code.

SYNTAX: The syntax for inheriting the two classes is:

class base_class_name

{

……………

public:

…………..

…………..

};

class derived_class_name : access_specifier base_class_name                //Now a derived class is inherit to a base class.

{

…………….

public:

…………….

…………….

};

 

 

Types of inheritance:

In c++, there are five different types of inheritance. each type of inheritance is differs from each others depending upon whether the class is derived from single base class or multiple base class or from an existing derived class. the five types of inheritance is:

1.Single Inheritance

2.Multiple Inheritance

3.Multi Level Inheritance

4.Hierarchical Inheritance

5.Hybrid Inheritance

Leave a Reply

Your email address will not be published. Required fields are marked *