ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
Integer a = 127;
Integer b = 127;
Integer c = 200;
Integer d = 200;
System.out.println((a == b) + " " + (c == d));
  1. A. true true
  2. B. true false
  3. C. false false
  4. D. false true

Correct answer: B. true false

Java caches boxed Integer objects for values from -128 to 127 (the Integer cache); autoboxing 127 twice returns the same cached object, so a==b is true. 200 is outside the cache range, so each autoboxing creates a distinct object, making c==d false — a classic autoboxing identity trap.

More OOP with C++ and Java questions

Exams that ask this topic