Static Methods and Inheritance
Consider the following class declarations.
public class Animal {
public static void makeSound() {
System.out.println("Some generic animal sound");
}
}
public class Dog extends Animal {
public static void makeSound() {
System.out.println("Bark");
}
}
The following code segment is executed in a method of a class other than Animal or Dog.
Animal animal = new Dog();
animal.makeSound();
What is the output when the code segment is executed?
A
Some generic animal sound
B
Some generic animal sound
Bark
C
Bark
D
Nothing is printed because the code does not compile.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE