Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Inheritance

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 460
    Comment on it

    In c++ inheritance is used in a concept of re-usability of code.In Inheritance there is a super/base class and sub/derived class. The base class act as a parent of the derived class. The derived class can inherit the properties of the base class.


    Instead of creating a new class with the same data members and member functions that has been previously defined in a different class, we can simply inherit that class and can reuse those data members and member functions. The existing class from which we are inheriting is called base/super class, and the class which is inheriting the properties is called derived/sub class.This is basically what we called the concept of "reusability of code".


    There are 5 types of inheritance available in c++:
    1. Single inheritance: a class can have only one parent.
    2. Multiple inheritance: a class can have more than one parent.
    3. Hierarchical inheritance: a parent class can have more than one child class.
    4. Multilevel inheritance: a child class act as a parent for another class.
    5. Hybrid inheritance: a combination of other four inheritance.




    alt text


    Syntax of inheritance:

    class A
    {
    ...........
    };
    class B : public A      <------- class B inherit class A
    {
    ...........
    };
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: