61 Program on Multilevel inheritance in Java

Code:

class A
{
int a = 111;
static int b = 222;

void m3()
{
System.out.println(" A-m3() ");
}

void m4()
{
System.out.println(" A-m4() ");
}

}

class B extends A
{
int c = 333;
static int d = 444;

void m1()
{
System.out.println(" B-m1() ");
}

void m2()
{
System.out.println(" B-m2() ");
}

}

class Test
{
public static void main( String[] args )
{
B obj = new B();

System.out.println("  Class A: ");
obj.m3();
obj.m4();
System.out.println(B.b+".."+obj.a);

System.out.println("  Class B: ");
obj.m1();
obj.m2();
System.out.println(B.d+".."+obj.c);

}
}


Output:


Previous
Next Post »