← Quiz: Wrapper Classes and Autoboxing: all 10 questions
Quiz: Wrapper Classes and Autoboxing · Question 2 of 10
What does the compiler turn Integer n = 42; into?
What does the compiler turn Integer n = 42; into?
- A.Integer n = new Integer(42);
- B.Integer n = Integer.valueOf(42);
- C.Integer n = Integer.parseInt(42);
- D.Integer n = (Integer) 42.0;
Answer & explanation
Correct answer: Integer n = Integer.valueOf(42);
Autoboxing calls valueOf, which is why boxed values can come from the cache.
Can you get the rest right without peeking?
Take the timed Quiz: Wrapper Classes and Autoboxing quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →