What is the output of the following code? “`java Integer a = 127; Integer b = 127; Integer c = 128; Integer d = 128; System.out.println(a == b); System.out.println(c == d); “`

Java Associate Hard

Java Associate — Hard

What is the output of the following code? “`java Integer a = 127; Integer b = 127; Integer c = 128; Integer d = 128; System.out.println(a == b); System.out.println(c == d); “`

Key points

  • Java caches Integer objects for values between -128 to 127
  • a and b point to the same object because they have the same value (127)
  • c and d do not point to the same object because c and d have different values (128)

Ready to go further?

Related questions