Which of these statements can fill in the blank so that the Main class compiles successfully?
(Choose all that apply.)
3: public class Main { 4: public static <U extends Exception> void printException(U u) { 5: System.out.println(u.getMessage()); 6: } 7: public static void main(String[] args) { 8: __________________________________ 9: } 10: }
A, B, D.
The generic type must be Exception or a subclass of Exception since this is an upper bound.
C and E are wrong because Throwable is a superclass of Exception.
D uses an odd syntax by explicitly listing the type, but you should be able to recognize it as acceptable.