Java SE 11 Developer (1Z0-819) — Question 63
Given the code fragment:
Integer i = 11;
Which two statements compile? (Choose two.)
Answer options
- A. Double c = (Double) i;
- B. Double b = Double.valueOf(i);
- C. Double a = i;
- D. double e = Double.parseDouble(i);
- E. double d = i;
Correct answer: B, E
Explanation
Option B is correct because Double.valueOf(i) correctly converts the Integer to a Double. Option E is also correct since assigning an Integer to a primitive double is permitted due to auto-unboxing. Options A, C, and D are incorrect as they involve invalid type casting or incorrect use of methods.