Multilevel Inheritance:


Source file Name: Multileveldemo.java

class A 

void sum(int a,int b) 

System.out.println("sum="+(a+b));

class B extends A 

void sub(int a,int b) 

System.out.println("substract="+(a-b)); }

class C extends B 

void sqcube(int n) 

int sq=n*n; 

int c=n*n*n; 

System.out.println("square="+sq+" cube="+c); } 

class Multileveldemo 

public static void main(String as[]) 

System.out.println("Inheritance program");

C ob=new C(); 

ob.sum(12,23); 

ob.sub(25,15); 

ob.sqcube(6); 

Output 

E:\sysem3>javac Multileveldemo.java

E:\sysem3>java Multileveldemo 

Inheritance program

sum=35 

substract=10 

square=36 cube=216