Given the code fragment:
Integer i = 11;
Which two statements compile? (Choose two.)
Given the code fragment:
Integer i = 11;
Which two statements compile? (Choose two.)
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.
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
B E tested
Answer: BE
B & E are correct TESTED
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.
Double b = Double.valueOf(i); and double d = i;