Skip to content
Sharp

Object-oriented programming · interview question

When comparing two String objects, what's the difference between == and equals()?

Multiple choiceEasy
Choose one answer
Answer and explanation

Correct answer

A. == compares references (same object); equals() compares the characters.

Why

For objects, == checks identity. String.equals checks content. Always use equals (or Objects.equals for null safety) for value comparison.

Test yourself on Object-oriented programming

A free test with instant, explained results. No account needed.

Start free test
All Object-oriented programming questions →