| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Iteration
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Integer Object Comparison
< Prev
Next >

Develop code to compare object references using Boolean expressions and determine the result of these expressions.

What is printed as a result of executing this code segment?

public static void compareObjects() {
    Integer x = 127;
    Integer y = 127;
    Integer z = 128;
    Integer w = 128;
    
    String result = "";
    
    if (x == y) {
        result += "A";
    }
    if (x.equals(y)) {
        result += "B";
    }
    if (z == w) {
        result += "C";
    }
    if (z.equals(w)) {
        result += "D";
    }
    
    System.out.println(result);
}
A

BD

B

AB

C

ABCD

D

ABD

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy