Polymorphism and Method Overriding
What is printed as a result of executing the following code segment?
class Animal {
void sound() { System.out.print("Animal "); }
}
class Dog extends Animal {
void sound() { System.out.print("Bark "); }
}
public class Main {
public static void main(String[] args) {
Animal a = new Dog();
a.sound();
}
}
A
Bark
B
Compilation Error
C
Animal
D
Animal Bark
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | zgj07310417 | 2 | 2 | 1m 14s | 126 |
| #2 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #3 | chrislee1274 | 1 | 1 | 0m 37s | 63 |
| #4 | lsj08030922 | 1 | 1 | 3m 31s | -111 |
| #5 | chunxiangxu.cxu | 0 | 1 | 11m 45s | -715 |
Items per page:
10
1 – 5 of 5
