Home » Learn C++ » Inheritance

Inheritance

Inheritance:

            Inheritance is the second most important feature of the Object Oriented Programming. In inheritance, the code of existing classes is used for making new classes. This saves time for writing and debugging the entire code for a new class.

            To inherit means to receive. In inheritance a new class is written such that it can access or use the members of an existing class. The new class that can access the members of an existing class is called the derived class or child class. The existing class is called the base class or parent class.

            The derived class can use the data members and member functions of the base class. It can also have its own data members and member functions. Thus a derived class can even be larger than a base class.

            The relationship between a derived class and the base class. The
arrow is drawn from the derived class to the base class. The direction of the arrow indicates that the derived class can access members of the base class but the he class cannot access members of its derived class.

            The derived class has only one member of its own. The two members shown in dotted lines are the members of the base class. The derived class can also access these two members of the base class. Thus, whereas an object of the base class can access two members, an object of the derived class can access three members.

            A new class can he derived from one or more existing classes. Based upon the number of base classes from which a class is derived, the inheritance is divided into two categories:

  • Single Inheritance
  • Multiple Inheritance

 
Single Inheritance:
In single inheritance, the new class is derived from only one base class.

Multiple Inheritances:
In multiple inheritances, the new class is derived from more than one base class.

 

Other Topics

comment closed

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.