Single level Inheritance

tutorial and example
tutorial and example

Inheritance is a feature in which one class inherits the property of another class. A class which inherits the property is called as derived class or sub class or child class and from which derived class inherits property is called as base class or patent class.

Inheritance makes reusability of code, which avoid rewriting the existing code again and again. A class can be driven from one class or from multiple base classes.

C++ Types of Inheritance

C++ provides different categories of inheritance depending upon the level and ways of properties inherited.

  • Single inheritance
  • Multilevel inheritance
  • Multiple inheritance
  • Hierarchical inheritance
  • Hybrid inheritance

Single Inheritance

Single inheritance is such inheritance in which single base class is inherited in only one derived class.

C++ Single Inheritance Example

A base class (Polygon) contains properties width, height and set_values which are inherited in derived class (Triangle).