Inheritance with c++




Definition  :        It is process of by which one class acquired the        property of another class.
  • New class is a derived class.
  • Exiting class known as base class.

šŸŽ‡Types of inheritance:

  1.    Single inheritance
  2.   Multiple inheritance
  3.   Multilevel inheritance
  4.   Hierarchical inheritance
  5.   Hybrid inheritance


1) single inheritance:The derived class only one based class is  called single inheritance.


  • A=base class
  • B=derived class

Syntax of single inheritance:
                                 


2)Multiple inheritance: A derived class with several base classes called multiple inheritance.


  • A=B=base class
  • C=derived class
   syntax :




3) Hhierarchical inheritance: A properties of one class may be       inherited by more than one class is called hierarchical inheritance.


  • A=base class
  • B=C=D=derived class

   syntax:


4)Multilevel inheritance: The mechanism of deriving a class from      another derived class is known as multilevel inheritance.
   syntax:

5)Hybrid inheritance: It is a combination of all type of inheritance.

syntax:



Syntax of inheritance:

 class  derived class name :: visibility mode base class name

EX.
base class define:                         Derived class :   
class B                                               class D : visibility mode B
{                                                           {           
private:                                                   private:
       .......                                                               .........
public:                                                     public:
       ........                                                              .......
};                                                            };


  • visibility  mode is optional and it is present either private or public.
  • Default visibility mode is private.
  • Visibility mode define the features of base class privately derived or publicly derived.




all type of inheritance with example in next post..

0 comments:

Copyright © 2013 free coding