public class Animal
{
public void eat()
{
System.out.println("Animal is eating");
}
}
Lion.java public class Lion extends Animal
{
@Override
public void eat()
{
System.out.sprintln("Lion is eating meat");
}
}
Cow.java public class Cow extends Animal
{
@Override
public void eat()
{
System.out.println("Cow is eating grass");
}
}
MethodOverrideTest.java public class MethodOverrideTest
{
public static void main(String[] args)
{
Animal animalRef = new Lion();
animalRef.eat();
animalRef = new Cow();
animalRef.eat();
}
}