Question 3
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Exam {
final int passMarks() { return 40; }
}
class EasyExam extends Exam {
@Override
int passMarks() { return 30; }
}
public class Main {
public static void main(String[] args) {
System.out.println(new EasyExam().passMarks());
}
}
- A EasyExam must be final
- B passMarks is final in Exam, so EasyExam cannot override it Correct
- C The return type must be long
- D @Override is not allowed on int methods
Correct Answer: Option B
javac: "passMarks() in EasyExam cannot override passMarks() in Exam; overridden method is final".
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!