In the Multilevel inheritance, a derived class will inherit a base class and as well as the derived class also act as the base class to other class. For example, three classes called A, B, and C, as shown in the below image, where class C is derived from class B and class B, is derived from class A. In this situation, each derived class inherit all the characteristics of its base classes. So class C inherits all the features of class A and B.
Example: Here, the derived class Rectangle is used as a base class to create the derived class called ColorRectangle. Due to inheritance the ColorRectangle inherit all the characteristics of Rectangle and Shape and add an extra field called rcolor, which contains the color of the rectangle.
This example also covers the concept of constructors in a derived class. As we know that a subclass inherits all the members (fields, methods) from its superclass but constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass. As shown in the below example, base refers to a constructor in the closest base class. The base in ColorRectangle calls the constructor in Rectangle and the base in Rectangle class the constructor in Shape.
Details of r1: Rectangle is Fibonacci rectangle Width and Length are 2 and 3.236 Color is pink Area is 6.472 Details of r2: Rectangle is Square Width and Length are 4 and 4 Color is black Area is 16