LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Predict the Output · Question 1

The Integer cache with == and equals Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

What is the output of the following Java program?

Main.java
public class Main {
    public static void main(String[] args) {
        Integer a = 100, b = 100, c = 1000, d = 1000;
        System.out.println((a == b) + " " + (c == d) + " " + c.equals(d) + " " + (c == 1000));
    }
}
  • A true false true true Correct
  • B true true true true
  • C false false true true
  • D true false true false
Correct Answer: Option A

100 comes from the cache; 1000 does not. c == 1000 unboxes c and compares ints.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links