ProgrammingHardCognizant GenC · HCL

What is printed?

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

Correct answer: D. true false

Autoboxing caches Integer objects from -128 to 127, so 127 shares one object while 128 creates two separate ones.

More OOP with C++ and Java questions

Exams that ask this topic