Inheritance is the capability of one class to inherit properties from another class as a child inherits some properties from his or her parents. The most important advantage of inheritance is code reusability. Once a base class is written and debugged, it can be used in various situations without having to redefine it or rewrite it. Reusing existing code saves time, money and efforts of writing the code again. Without redefining the old class, you can add new properties to desired class and redefine an inherited class member function.
Inheritance is one of the important concepts of object-oriented language. There are several reasons why this concept was introduced in object oriented language. Some major reasons are:
The mechanism of deriving a new class from an old one is called inheritance (or derivation). The old class is referred to as the base class and new one is called the derived class. There are various forms of inheritance:
A derived class is defined by specifying its relationship with the base class using visibility mode.
The general form of defining a derived class is:
class derived_class : visibility_mode base_class
_________________ // members of derived class.
The colon indicates that the derived_class is derived (inherits some property) from base_class.
It can be public, private or protected. The private data of base class cannot be inherited.
The data present in private section of base class cannot be inherited. The difference between private and protected section is that data present in protected section can be inherited. Otherwise both the section cannot be accessed by the object of the class.
An abstract class is one that is not used to create objects. An abstract class is designed only to act as a base class (to be inherited by other classes). It is a design concept in program development and provides a base upon which other classes may be built.