Programs of multilevel inheritance

Program
class A
{
public void method1()
{
System.out.println(“Class A method”);
}
}
class B extends A
{
public void method2()
{
System.out.println(“class B method”);
}
}
class test extends B
{
public void method3()
{
System.out.println(“class test method”);
}
public static void main(String args[])
{
test obj = new test();
obj.method1();
obj.method2();
obj.method3();
}
}

Output:
Class A method
class B method
class test method

Program
class one
{
protected String str;
one()
{
str = “This “;
}
}
class two extends one
{
two()
{
str = str.concat(“is “);
}
}
class three extends two
{
three()
{
str = str.concat(“Basicofy”);
}
}
class four extends three
{
four()
{
str = str.concat(“.com”);
}
void display()
{
System.out.println(str);
}
}
class test
{
public static void main(String args[])
{
four obj = new four();
obj.display();
}
}

Output:
This is Basicofy.com

Leave a Reply

Your email address will not be published. Required fields are marked *