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

Given:

What is the output?

    Correct Answer: C

    The code snippet uses the Java Optional class to handle the nullable value. The method createValue() returns an Optional containing the value of s, which is null. Therefore, the Optional is empty. The method orElse() is used to provide a fallback value when the Optional is empty. In this case, the fallback value is 'Duke'. So, when value.orElse('Duke') is called, it returns 'Duke', which is then printed to the console.

Discussion
d7bb0b2Option: C

C: cause ofNullable(null) return an empty optional

OmnisumemOption: C

tested: C

StavokOption: C

C is correct