Sail E0 Webinar
Question
What is the result of compiling and running this program?class Mammal{ void eat(Mammal m){ System.out.println("Mammal eats food"); }}class Cattle extends Mammal{ void eat(Cattle c){ System.out.println("Cattle eats hay"); }}class Horse extends Cattle{ void eat(Horse h){ System.out.println("Horse eats hay"); }}public class Test{ public static void main(String[] args){ Mammal h = new Horse(); Cattle c = new Horse(); c.eat(h); }}
Options:
A .  None of these
B .  Class cast Exception at runtime.
C .  prints "Cattle eats hay"
D .  prints "Horse eats hay"
E .  prints "Mammal eats food"
Answer: Option E

Submit Your Solution Below and Earn Points !
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers