12 Sept 2019

  • September 12, 2019
  • Amitraj
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.


Modes of inheritance
  1. Public mode: If we derive a sub class from a public base class. Then the public member of the base class will become public in the derived class and protected members of the base class will become protected in derived class.
  2. Protected mode: If we derive a sub class from a Protected base class. Then both public member and protected members of the base class will become protected in derived class.
  3. Private mode: If we derive a sub class from a Private base class. Then both public member and protected members of the base class will become Private in derived class.
Note : The private members in the base class cannot be directly accessed in the derived class, while protected members can be directly accessed.
                                   
*Full Description About Inheritance
Inheritance:- Reusing the existing code without defining it again and again.

*Different types of inheritance in C++:-
1.) single inheritance
2.) multiple inheritance
3.) multilevel inheritance
4.) Hierarchical inheritance
5.) Hybrid inheritance

** C++ strongly supports the concept of Reusability. The mechanism of  deriving a new class from an old one is called ,inheritance.

-> The old class is reffered to as "Base class" or "Parent class" or "super class".

-> The new class is reffered to as "Derived class" or "child class" or "sub class".





Translate

Popular Posts