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

Given the code fragment:

Integer i = 11;

Which two statements compile? (Choose two.)

    Correct Answer: B, E

    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
ASPushkinOptions: BE

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

mendjijetOptions: BE

B E tested

tmuralimanoharOptions: BE

Answer: BE

StavokOptions: BE

B & E are correct TESTED

Stavok

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.

JticOptions: BE

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