types of inheritance

Introduction to Inheritance in C++

Let me introduce you to the concept of Inheritance in C++. Reusability is yet another important feature of C++. It is always nice if we could reuse something that already exists rather than trying to create the same all over again. It would not only save the time and money but also reduce frustration and increase readability. For instance, the reuse of a class that has already been tested, debugged and used many time can save us the effort of developing and testing the same again. Fortunately, C++ strongly supports the concept of reusability.The C++ classes can be reused in several ways. Once a class has been written and tested, it can be adapted by other programmers to suit their requirements. This is basically done by creating new classes which reuse the properties of the existing ones. The mechanism of deriving a new class from an old one is called...

Multi-Level Inheritance in C++

The mechanism of deriving a class from another derived class is known as multi-level inheritance in C++ It is not uncommon that a class is derived from another derived class as shown below: The class A serves as a base class for the derived class B which in turn serves as a base class for the derived class C. The class B is known as intermediate base class since it provides a link for the inheritance between A and C. The chain A -> B -> C is known as inheritance path. A derived class with multi-level inheritance is declared as follows: class A //Base Class { … }; class B : public A //B derived from A { … }; class C : public B //C derived from B { … }; This process can be extended to any number of levels. Let us consider the below example: Assume...