Programs of single inheritance

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

Output:
Super class method
Sub class method

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

Output:
hello!!! This is Basicofy.com

 

Leave a Reply

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