Write a Java Program to implement inheritance and demonstrate use of method overriding.

Program Code:
import java.lang.*;
class A
{
void display()
{
System.out.println("This is from class A ");
}
}
class B extends A
{
void display()
{
System.out.println("This is from class B ");
}
}
class AB
{

public static void main(String arg[])
{
B obj=new B();
obj.display();
}
}

Output:
This is from class B
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: