Question 7
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Payment {
final double gst(double amount) { return amount * 0.18; }
}
class ExportPayment extends Payment {
@Override
double gst(double amount) { return 0; }
}
public class Main {
public static void main(String[] args) {
System.out.println(new ExportPayment().gst(100));
}
}
- A gst must be static
- B gst is final in Payment, so ExportPayment cannot override it Correct
- C ExportPayment must be final
- D 0 must be 0.0
Correct Answer: Option B
Remove final in the parent if subclasses should change it, or add a separate overridable hook.
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!