🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Integer n = new Integer(42);
  2. B.Integer n = Integer.valueOf(42);
  3. C.Integer n = Integer.parseInt(42);
  4. 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 →