Inheritance in C++

The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important feature of Object Oriented Programming. 
Sub Class: The class that inherits properties from another class is called Sub class or Derived Class. 
Super Class: The class whose properties are inherited by sub class is called Base Class or Super class. 
Consider a group of vehicles. You need to create classes for Bus, Car and Truck. The methods fuelAmount(), capacity(), applyBrakes() will be same for all of the three classes. If we create these classes avoiding inheritance then we have to write all of these functions in each of the three classes
Using inheritance, we have to write the functions only one time instead of three times as we have inherited rest of the three classes from base class (Vehicle).
Implementing inheritance in C++: For creating a sub-class which is inherited from the base class we have to follow the below syntax. 

Syntax:

class subclass_name : access_mode base_class_name
{
  // body of subclass
};

Posted on by