public class Animal {
public void eat() {
System.out.println("I eat like a generic Animal.");
}
public static void main(String[] args) {
}
}
class Fish extends Animal {
@Override
public void eat() {
System.out.println("I eat like a fish!");
}
}
class Goldfish extends Fish {
@Override
public void eat() {
System.out.println("I eat like a goldfish!");
}
}
In this example how to call the 'eat' method of the Animal class using an object of class GoldFish?
GoldFish gfobj = new GoldFish();
gfobj.eat();//i'm expecting this line to call the eat method in the Animal class
however i'm aware of
Animal aobj = new Fish();
aobj.eat();//this will print "I eat like a fish!"