1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 101


Given the code fragment:

What change on line 1 will make this code compile?

Show Answer
Correct Answer: B

In Java, the exception M is a subclass of L and thus can be caught by a catch block that handles exceptions of type L. Therefore, adding catch(L e) is sufficient to catch both M and L exceptions, making the code compile successfully. Catching L will automatically catch both M and L exceptions because M extends L. Other options like catching multiple exceptions with a multi-catch block are unnecessary and may result in compilation errors if subclasses are included inappropriately.

Discussion

5 comments
Sign in to comment
StavokOption: B
Jul 19, 2023

B is correct Tested

[Removed]Option: B
Aug 30, 2023

B is the most correct one. But D will also compile

dilleman
Sep 29, 2023

B and D will compile (tested).

d7bb0b2Option: B
Jan 8, 2024

B is correct, is just a change needs to compile, D=> is also correct but the answer that are nor releated excepcion but, with B opcion can capture All expcionts

ASPushkinOption: B
Jun 15, 2024

answer : BD Exception classes specified inmulticatch statement cannot be subclasses. The order of the exception classes does not affect its execution. A,C,E - not correct - subclasses