Multilevel inheritance

 Multilevel Inheritance
A class can also be derived from one class, which is already derived from another class.
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.

Multilevel inheritance refers to a mechanism in OO technology where one can inherit from a derived class, thereby making this derived class the base class for the new class. 
Multilevel Inheritance example program in Java


Class X
{
   public void methodX()
   {
     System.out.println("Class X method");
   }
}
Class Y extends X
{
public void methodY()
{
System.out.println("class Y method");
}
}
Class Z extends Y
{
   public void methodZ()
   {
     System.out.println("class Z method");
   }
   public static void main(String args[])
   {
     Z obj = new Z();
     obj.methodX(); //calling grand parent class method
     obj.methodY(); //calling parent class method
     obj.methodZ(); //calling local method
  }
}


Posted on by