Username   Password       Register

Inheritance

Inheritance is the property of one class to inherit the properties of an another class. Major reason behind inheritance is reusability. The mechanism of deriving a new class from an old or existing class is called i nheritance (derivation). The old class is referred to as the base class and new class is called derived class or sub class. The derived class inherits some or all of the traits from the base class.

A class can also inherit properties from more than one class, for more than one level.

Types of inheritance

  • Single inheritance
  • Multiple inheritance
  • Hierarchical inheritance
  • Multi level inheritance
  • Hybrid inheritance

Deriving a Class

The private derivation means that the derived class can access the public and the protected members of the base class privately. With privately derived class, the public and the protected members of the base class become private members of the derived class.

Visibility of inherited members

Base class visibility Derived class visibility
Public Private Protected
Private Not inherited Not inherited Not inherited
Protected Protected Private Protected
Public Public Private protected

Single level Inheritance

Multi level inheritance

blog comments powered by Disqus

Discuss Inheritance in the forums.

 
(0 - user rating)