Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Engine {
String start() { return "vroom"; }
}
class TestEngine extends Engine {
static String start() { return "test start"; }
}
public class Main {
public static void main(String[] args) {
System.out.println(TestEngine.start());
}
}
- A TestEngine must be abstract
- B A static method cannot override (or hide) an inherited instance method with the same signature Correct
- C Strings cannot be returned from static methods
- D start must be final
Correct Answer: Option B
javac: "start() in TestEngine cannot override start() in Engine; overriding method is static".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!