I'm relatively new to the topic of polymorphism and inheritance, but I've had a burning question. Consider this code:
public class Food {
public static void eat() {
System.out.println("This food is great.");
}
}
public class Cake extends Food {
public static void eat() {
System.out.println("This cake is great.");
}
}
Of course, you could instantiate a Cake object like this:
Cake c = new Cake();
but I've also been told you could instantiate a Cake object like this:
Food c = new Cake();
My question is: What's the difference between the two? I do not see the point of the second one but I'm sure there has to be a situation where it would be useful?