Question 8
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Base {
private void log() { System.out.println("base log"); }
}
class Derived extends Base {
@Override
void log() { System.out.println("derived log"); }
}
public class Main {
public static void main(String[] args) {
new Derived().log();
}
}
- A log must be static
- B Base.log is private and not inherited, so Derived.log overrides nothing and @Override is an error Correct
- C Derived must call super.log()
- D void methods cannot be overridden
Correct Answer: Option B
Without @Override it would compile as an unrelated method.
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!