1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 79


Given the code fragment:

Integer i = 11;

Which two statements compile? (Choose two.)

Show Answer
Correct Answer: BE

To determine which statements compile, it's important to understand type conversions in Java. The expression 'Double.valueOf(i)' correctly compiles because it converts an Integer i to a Double object. The statement 'double d = i' also compiles because it involves unboxing the Integer i to an int and then widening it to a double. The other statements either involve illegal type casts or incorrect type conversions that do not compile.

Discussion

5 comments
Sign in to comment
JticOptions: BE
Feb 21, 2023

Double b = Double.valueOf(i); and double d = i;

StavokOptions: BE
Jun 7, 2023

B & E are correct TESTED

Stavok
Jul 18, 2023

the Double.valueOf() method takes an Integer argument and returns a Double object. In statement E, the Integer object i is unboxed to an int primitive and then widened to a double primitive.

tmuralimanoharOptions: BE
Jun 29, 2023

Answer: BE

mendjijetOptions: BE
Feb 8, 2024

B E tested

ASPushkinOptions: BE
Jul 9, 2024

AC failed incompatible types B. correct Integer autoboxing in int int widenning casting to double D failed incompatible types: Integer cannot be converted to String E correct