The mechanism of deriving a class from another class is known as inheritance.
The class from which another class is derived is called as the base class.
While the class which is derived is called as derived class.
Assigning a property of class to an object of another class is termed as inheritance.
5types of inheritance
- The protected access specifier restricts access to member functions of the same class, or those of derived classes
Hybrid inheritance is combination of two or more inheritances such as single,multiple,multilevel or Hierarchical inheritances.
In the below program class B inherits property(member function) of class A which is base class and class D inherits property from class B and class C.
class A //Base class
cout<<" Lenght ::: ";
class B : public A //Inherits property of class A
cout<<" Breadth ::: ";
cin>>b; //Breadth is enter by user
c=b*l; //c stores value of lenght * Breadth i.e. (l*b) .
cout<<" Height ::: ";
cin>>h; //Height is enter by user
//Hybrid Inheritance Level
class D: public B, public C
res=h*c; //res stores value of c*h where c=l*b and h is height which is enter by user
cout<<" Result (l*b*h) ::: "<<res;