Java SE 11 Developer — Question 14
Which two are successful examples of autoboxing? (Choose two.)
Answer options
- A. String a = “A”;
- B. Integer e = 5;
- C. Float g = Float.valueOf(null);
- D. Double d = 4;
- E. Long c = 23L;
- F. Float f = 6.0;
Correct answer: A, B
Explanation
Options A and B are correct because autoboxing involves converting a primitive type into its corresponding wrapper class, and in these cases, the integer 5 is automatically converted to an Integer object, and the string 'A' is a valid assignment. Options C, D, E, and F either do not involve autoboxing or contain invalid assignments, such as using null with Float.valueOf or directly assigning a primitive to a wrapper without autoboxing.