Inheritance is the most common and exciting feature of C++ which provides the reusability. Reusability means to use what we have rather than develop same again (In oops classes are reused).
- To reuse the existing classes or their features of the class must be extended.
- The class that is already exists, is known as base class/super class. Or class which taking features of existing class is known as child class/sub class/derived class.
//members of subclass
Note : visibility mode is optional, default is private.
- When sub class/base class is inheriting the super class with private access modifier then public members of super class will become private members of derived class.
- When base class is inheriting the super class with public accessible mode then public members of base class will become public that means no change.
- Private data members are not inherited. They wont go to the derived class.
- Single inheritance
- Multilevel inheritance
- Multiple inheritance
- Hierarchical inheritance
- Hybrid inheritance
If a class derived from one base class only means only one base class or one child class.
#define SIZE 25
cout<<”enter name = “;
cout<<”enter your age= “;
cout<<”name is= “<
class student:protected Person
cout<<”enter your rollnumber”;
void student ::display()
cout<<”roll no is=”<