Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Iteration
Start Practice TestPractice Test
About Exam
easy Solved by 2 students

Java Object Reference Comparison

Mark
< Prev
Next >

Consider the following compareStudents method.

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

Assume that s1 and s2 are non-null Student objects and that the getName method returns a non-null String. Under which of the following conditions will the method return true?

A

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

B

Only when s1 and s2 reference the same Student object

C

Never, because the expression contains a logical error

D

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

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.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|