Inheritance is the most important feature provided by Object Oriented Programming. The main purpose of inheritance is the re-usability of the existing class. Using inheritance it is possible to derive one or more new classes from existing one or more classes. Here derived class have their own properties along with they can have properties of base(original) class/classes.
There are different types inheritances available. They are
1) Simple or Single inheritance. Here there is only one base class and only one derived class.
2) Multiple inheritance. Here term multiple is used for base classes. So this type of inheritance have at least two base classes with one derived class.
3) Multilevel inheritance. When derived class becomes base class for further inheritance, the concept is called as multiple inheritance.
4) Hierarchical inheritance. When one base class has more than one derived classes then it is known as hierarchical inheritance.
5) Hybrid inheritance. When more than one inheritances are used together then the term is known as hybrid inheritance.
Syntax for declaring derived class from base class is as follows
class derived class_name: visibility mode base class_name
Syntax for declaring derived class in case of multiple inheritance is as below
class derived class_name : visibility mode base class1, visibility mode base class2, .....
Syntax for declaring derived class in case of multilevel inheritance is as follows
class derived class1 : visibility mode base class
class derived class 2:visibility mode class1
Below is the program to implement single/simple inheritance.
//PROGRAM TO IMPLEMENT SINGLE INHERITANCE
cout<<"Enter employee number and employee name\n";
cout<<"\nEmployee name is "< cout<<"\nEmployee number is "< }
class fitness:public employee
float height, weight,r;
cout<<"\nEnter height and weight\n";
cout<<"\nEmployee height is "< cout<<"\nEmployee weight is "< }
class fitness f;
cout<<"\nDetails of employee are as follows\n";
Please include and header files before class declaration.