Java SE 11 Developer (1Z0-819) — Question 3
Given the code fragment:
List<Integer> list = List.of(11,12,13,12,13);
Which statement causes a compile time error?
Answer options
- A. Double d = list.get(0);
- B. double f = list.get(0);
- C. Integer a = Integer.valueOf(list.get(0));
- D. Integer b = list.get(0);
- E. int c = list.get(0);
- F. Double e = Double.valueOf(list.get(0));
Correct answer: A
Explanation
The correct answer is A because the method list.get(0) returns an Integer, and trying to assign it directly to a Double variable will cause a compile-time error due to type incompatibility. Options B, C, D, E, and F either correctly convert the Integer to a primitive or use appropriate type assignments without type mismatch.