Multi level inheritance
- A class is derived from another derived class is called Multilevel inheritance
--------------------------------------------------------------------------
Program : Single Inheritance
Program name : MultilevelDemo.java
Output :
Parent1 i value is : 1
Child1 j value is : 2
Child2 k value is : 3
class Parent1
{
int i = 1;
public void m1()
{
System.out.println("Parent1 i value is : "+i);
}
}
class Child1 extends Parent1
{
int j = 2;
public void m2()
{
System.out.println("Child1 j value is : "+j);
}
}
class Child2 extends Child1
{
int k = 3;
public void m3()
{
System.out.println("Child2 k value is : "+k);
}
}
class MultilevelDemo
{
public static void main(String args[])
{
Child2 ch = new Child2();
ch.m1();
ch.m2();
ch.m3();
}
}
Compile : javac MultilevelDemo.java
Run : java MultilevelDemo
Output :
Parent1 i value is : 1
Child1 j value is : 2
Child2 k value is : 3
--------------------------------------------------------------------------
Thanks for your time.
Thanks for your time.
Nireekshan