Multilevel Inheritance : In the case of the multilevel inheritance, we first create a derived class on the basis of the single base class. Then on the basis of this derived class, we create another derived class and so on...
PROGRAM
class A
{
private int a;
public void setA(int i)
{
a=i;
}
public void showA( )
{
System.out.println("a="+a);
}
}
class B extends A
{
private int b;
public void setB(int j)
{
b=j;
}
public void showB( )
{
System.out.println("b="+b);
}
}
class C extends B
{
private int c;
public void setC(int k)
{
c=k;
}
public void showC( )
{
System.out.println("c="+c);
}
}
class MutiLevel
{
public static void main(String args[ ])
{
C
ob=new C( );
ob.setA(5);
ob.setB(10);
ob.setC(15);
ob.showA();
ob.showB();
ob.showC();
}
}
Comments
Post a Comment