Oracle
1Z0-851 · Question #258
Given: abstract class Vehicle { public int speed() { return 0; } class Car extends Vehicle { public int speed() { return 60; } class RaceCar extends Car { public int speed() { return 150; }…
The correct answer is D. 150, 150, 150. See the full explanation below for the reasoning.
Question
Given: abstract class Vehicle { public int speed() { return 0; } class Car extends Vehicle { public int speed() { return 60; } class RaceCar extends Car { public int speed() { return 150; } ... RaceCar racer = new RaceCar(); Car car = new RaceCar(); Vehicle vehicle = new RaceCar(); System.out.println(racer.speed() + ", " + car.speed() + ", " + vehicle.speed()); What is the result?
Options
- A0, 0, 0
- B150, 60, 0
- CCompilation fails.
- D150, 150, 150
- EAn exception is thrown at runtime.
How the community answered
(32 responses)- B3% (1)
- C6% (2)
- D81% (26)
- E9% (3)
Community Discussion
No community discussion yet for this question.