C++ Inheritance

C++ Inheritance


C++ Inheritance
It is the capability of one class (base class) to inherit properties from another class or classes (child class). The technique of building new from the existing classes is called inheritance.
Inheritance – Terminology and Notation in C++ are as follows:
Base Class- 
  • It is the class whose properties are inherited by another class.
  • It is also called Super class or Parent class.
Drived  Class-
  • It is the class that inherits properties from base class or classes.
  • It is also called Sub class or Child class.
  • It is inherited that all properties of the base class can add additional features to the drived class.
The "is a" Relationship
The Syntax of inheritance is as follows:
class A {
...
}
class B: Public A {
...
}
Here, is the name of the sub class, accessSpecifier is the mode in which you want to inherit this sub class for example: public, private etc. and is the name of the base class from which you want to inherit the sub class. 
Note: A derived class doesn’t inherit access to private data members. However, it does inherit a full parent object, which contains any private members which that class declares.
Class Access Specifiers
  1. public – object of derived class can be treated as object of base class (not vice-versa)
  2. protected – more restrictive than public, but allows derived classes to know details of parents
  3. private – prevents objects of derived class from being treated as objects of base class.
Example
Output
There are five types of Inheritance in C++ are as follows:
  1. Single inheritance
  2. Multi-Level Inheritance
  3. Multiple Inheritance
  4. Hierarchical Inheritance
  5. Hybrid Inheritance