Form of inheritance
A class can inherit properties from one or more classes and
from one or more levels.
On the basis of this concept, there are five forms of inheritance. - Single inheritance
- Multiple inheritance
- Hierarchical inheritance
- Multilevel inheritance
- Hybrid inheritance
2) Multiple inheritanceIn this inheritance, a class is derived from more than one base class. The example and figure below show this inheritance.Example:-#include <iostream>#include<conio.h>using namespace std;class Teacher{int tid;char subject[20];public:void getTeacher(){cout<<"Enter Teacher id and subject"<<endl;cin>>tid>>subject;}void displayTeacher(){cout<<"Teacher ID::"<<tid<<endl;cout<<"Subject::"<<subject<<endl;}};class staff{int sid;char level[10];public:void getStaff(){cout<<"Enter staff ID and level"<<endl;cin>>sid>>level;}void displaystaff(){cout<<"Staff ID:"<<sid<<endl;cout<<"Level::"<<level<<endl;}};class coordinator: public Teacher, public staff{char program[10];public:void getdata(){getTeacher();getStaff();cout<<"Enter Program"<<endl;cin>>program;}void displaydata(){displayTeacher();displaystaff();cout<<"Program::"<<program;}};int main(){coordinator c;c.getdata();cout<<"----------------coordinator Details-----------------"<<endl;cout<<"***************************************************"<<endl;c.displaydata();getch();return 0;}Output:-
0 comments:
Post a Comment