🎙 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 1 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        Integer x = 100, y = 100;
        Integer p = 1000, q = 1000;
        System.out.println((x == y) + " " + (p == q));
    }
}
  1. A.true true
  2. B.true false
  3. C.false false
  4. D.false true
Answer & explanation

Correct answer: true false

100 is inside the Integer cache (−128 to 127), so x and y are the same object. 1000 is outside, so p and q are different objects.

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 →