Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class ValidationException<T> extends Exception {
private static final long serialVersionUID = 1L;
final T badValue;
ValidationException(T badValue) { this.badValue = badValue; }
}
public class Main {
public static void main(String[] args) {
System.out.println("validate");
}
}
- A badValue must be private
- B A generic class may not extend Throwable, because catch clauses need the exact type at run time and T would be erased Correct
- C Exception classes cannot have fields
- D serialVersionUID must be public
Correct Answer: Option B
Store the bad value as Object (or make specific exception classes).
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!