Polymorphism and Method Overriding
What will be printed when the program is executed?
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
Compilation Error
B
Animal Bark
C
Animal
D
Bark
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | chrislee1274 | 1 | 1 | 0m 37s | 63 |
| #3 | lsj08030922 | 1 | 1 | 3m 31s | -111 |
Items per page:
10
1 – 3 of 3
APFIVE