Single Choice
Not Set
QWhat 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);
}
}
ID: #2257
Inheritance in Java MCQ
3,407 views
Question Info
#2257Q ID
Not SetDifficulty
Inheritance in Java MCQTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
prints "Mammal eats food"
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic