source file name: OverrideSuperDemo.java
class Human{
//Overridden method
public void eat()
{
System.out.println("Human is eating anyhings");
}
}
class Person extends Human{
//Overriding method
public void eat()
{
super.eat();
System.out.println("Person is eating veg or non-veg things");
}
}
class OverrideSuperDemo
{
public static void main( String args[])
{
Person obj = new Person();
//This will call the child class version of eat()
obj.eat();
}
}
output:
D:\JavaPrograms>javac OverrideSuperDemo.java
D:\JavaPrograms>java OverrideSuperDemo
Human is eating anyhings
Person is eating veg or non-veg things
0 Comments
Post a Comment