Inheritance 1
Inheritance 1
Sub Class: The class that inherits properties from another class
is called Sub class or Derived Class.
Advantages
reusability and readability When child class inherits the
properties and functionality of parent class, we need not to
write the same code again in child class. This makes it easier to
reuse the code, makes us write the less code and the code
becomes much more readable.
Implementing inheritance in C++
For creating a sub-class which is inherited from the base class
follow the below syntax.
Syntax:
Class subclass_name : access_mode base_class_name
{
//body of subclass
};
Syntax:
Syntax:
class subclass_name : access_mode base_class1, access_mode base_class2, ....
{
//body of subclass
};
Here, the number of base classes will be separated by a comma (‘, ‘) and access
mode for every base class must be specified.