40.method overriding
//method overriding
class parent
{
void show(String str)
{
System.out.println("Parent class -" + str);
}
}
class child extends parent
{
void show(String s)
{
System.out.println("Child class - " + s);
super.show("show method is called");
}
}
class method_overring
{
public static void main(String[] args) {
child obj = new child();
obj.show("show method is called");
}
}
OUTPUT:
Child class - show method is called
Parent class -show method is called
Comments
Post a Comment