In "Hierarchical Inheritance" their is only one Parent class and 'n' numbers of Child class.
Basically their is only one Parent class which have a lot of Child class sharing the same properties. This type of inheritance is used when we need to share the same type of behavior / properties / functions to a number of different classes.
Syntax:-
Basically their is only one Parent class which have a lot of Child class sharing the same properties. This type of inheritance is used when we need to share the same type of behavior / properties / functions to a number of different classes.
Block-Diagram
Syntax:-
Example of Hierarchical Inheritance
#include<iostream> using namespace std; class Name { protected: char name[20]="Mr C"; }; class Marks:public Name { public: int total_marks=90; void put() { cout<< name<<" have got Total marks: "<<total_marks; cout<<endl; } }; class Academic_Details:public Name { public: int Redg_no=123456; void put() { cout<<name <<" have the Registration number: "<< Redg_no; } }; int main() { Marks x; Academic_Details y; x.put(); y.put(); }
0 Comments