← 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));
}
}
- A.true true
- B.true false
- C.false false
- 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 →