Skip to content
Sharp

Object-oriented programming · interview question

What will happen if you copy an object reference to another variable and then modify the object via the new reference?

Multiple choiceMediumchapter-2-curatedpremiumoopobject-references
Choose one answer
Answer and explanation

Correct answer

D. Both references will reflect the changes.

Why

In Java, object references point to the same memory location. Modifying the object through one reference affects all references pointing to that object.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →