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".




Related Posts:

  • C++ Standered Template Library (STL) C++ Standered Template Library (STL) Template can be used to create generic classes and functions that could extend supports for Generic programming.     -> In order to help the C++ users in generic programming… Read More
  • Components of Standered Template Library (STL) Components of Standered Template Library (STL) The STL contains several components but at its core are 3 key components:-     They are- 1. Container 2. Algorithm 3. Iterators -> The Relatonship between The 3… Read More
  • C++ Stream classes Structure C++ Stream classes Structure -> The C++ I/O system contains a hierarchy of classes that are used to define various streams to deal with both the console and disk files, These classes are called Stream classes. -> Str… Read More
  • C++ File I/O Operations on Characters C++ File I/O Operations on Characters #include<iostream> using namespace std; #include<fstream> #include<cstring> int main() { char string[80]; cout<<"Enter a string:"; cin>>string; int len… Read More
  • Containers and Applications of Container Classes in STL Containers:- Containers are objects that hold data. The STL defines Ten containers which are grouped into three categories. 1. Sequence Containers     Sequence containers store elements in a linear sequ… Read More

Translate

Popular Posts