# Multiple-level inheritance

Multiple-level inheritance: As three classes called A, B, C.C can be a subclass of B, which is a subclass of A.to see how a multi-level hierarchy can be useful, consider the following program. In it, the subclass Box Weight is used as a superclass to create the subclass called Shipment.
1.Example of Multiple-level Inheritance

``````import java.util.*;
class A
{
int a=10,total=0;
void funA()
{
System.out.println("Value of a is"+a);
System.out.println("Total is"+total);
}
}
class classB extends classA //SubCLass //extending SuperClass
{
int b=20;
void funB()
{
total=a+b;
System.out.println("Value of a is"+a);
System.out.println("Value of b is"+b);
System.out.println("Total is"+total);
}
}
class classC extends classB //Sub Class(acting as a super class)
{
int c=30;
void funC()
{
total=a+b+c;
System.out.println("Value of a is"+a);
System.out.println("Value of b is"+b);
System.out.println("Value of c is"+c);
System.out.println("Total is"+total);
}
}
class Multilevel
{
public static void main(String args[])
{
classA a=new classA();
classB b=new classB();
classC c=new classC();
c.funA();
c.funB();
c.funC();
}
}
OUTPUT:
Value of a is10
Total is 0
Value of a is 10
Value of b is 20
Total is 30
Value of a is 10
Value of b is 20
Value of c is 30
Total is 60``````
Translate »