Program on Method Overriding.
class Super
{
int x;
Super(int x)
{
Thi.x=x;
}
Void display()
{
System.out.println(“Super
X=”+x);
}
}
Class Sub
extends Super
{
int y;
Sub(int x, int y)
{
Super(x);
This.y=y;
}
Void display
{
System.out.println(“SuperX=”+x);
System.out.println(“Sub
Y=”+y);
}
}
Class
Override
{
Public static void main(String
s[])
{
Sub obj=new
Sub(100,200);
Obj.display();
}
}
Output
Super X=100
Sub Y=200
0 Comments
Please share your opinions and suggestions with us.