Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 152

Given the code fragment:

What is the output?

    Correct Answer: A

    The code will throw a runtime exception. The List.of() method creates an immutable list, which means it cannot be modified. Any attempt to add elements to this list using the add() method will result in an UnsupportedOperationException. Therefore, when the code tries to add elements to the list, this exception will be thrown.

Discussion
KiraguJohnOption: A

A because List.of(...) is an immutable list you can't modify

ASPushkinOption: A

- The List.of and List.copyOf static factory methods provide a convenient way to create unmodifiable lists. The List instances created by these methods have the following characteristics: - They are unmodifiable. Elements cannot be added, removed, or replaced. Calling any mutator method on the List will always cause runtime UnsupportedOperationException to be thrown. However, if the contained elements are themselves mutable, this may cause the List's contents to appear to change public class UnsupportedOperationException extends RuntimeException

StavokOption: A

A is correct