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

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

Consider this method that compares two Student objects:

public boolean compareStudents(Student s1, Student s2) {
    return s1 == s2 && s1.getName().equals(s2.getName());
}

Assume s1 and s2 are non-null and getName() returns a non-null String. Under which condition will this method return true?

A

When s1 and s2 are different objects but have the same name

B

When s1 and s2 have the same name, regardless of whether they’re the same object

C

Only when s1 and s2 reference the same Student object

D

Never, because the expression contains a logical error

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