Hierarchical Inheritance in C++ Programming
Inheritance is the process of inheriting properties of objects of one class by objects of another class. The class which inherits the properties of another class is called Derived or Child or Sub class and the class whose properties are inherited is called Base or Parent or Super class. When more than one classes are derived from a single base class, such inheritance is known as Hierarchical Inheritance, where features that are common in lower level are included in parent class. Problems where hierarchy has to be maintained can be solved easily using this inheritance.
For example,
- Civil, Computer, Mechanical, Electrical are derived from Engineer.
- Natural language, Programming language are derived from Language.
Syntax of Hierarchical Inheritance
class base_classname { properties; methods; }; class derived_class1:visibility_mode base_classname { properties; methods; }; class derived_class2:visibility_mode base_classname { properties; methods; }; ... ... ... ... ... ... class derived_classN:visibility_mode base_classname { properties; methods; };