An object-model interview answer should distinguish reference values, object state, dispatch, and equality rather than treating them as one concept.
Java object interview questions: references, equality, and constructors
Java 8+. Use a JDK that supports this release.
Does assignment copy an object?
No. Assigning a reference gives another variable a reference value to the same object. Mutating that object through either route can be observed through the other. Reassigning one variable changes only that variable.
Follow-up: what does an array copy do? It copies primitive values or element references. For a list of mutable receipt objects, copying the list structure still shares those receipt objects. State which ownership boundary is required before proposing a copy.
Can a final reference point to mutable state?
Yes. final prevents reassigning that variable after initialization; it does not freeze the referenced collection. The probe below changes a list through a final reference and prints the resulting size.
Follow-up: when does an unmodifiable view change? It can reflect writes performed through another reference to its backing collection. A detached structural snapshot has a different contract.
What breaks a hash key?
Changing equality-relevant state after insertion can make lookup fail or create a logically inconsistent key set. The map uses the key’s hash and equality during its operations; it does not monitor arbitrary field writes.
Follow-up: should two separately loaded receipts be equal? That is a domain rule, usually based on a stable identifier or immutable value components. Default Object equality uses identity. Read the key contract.
Why avoid overridable constructor calls?
Dispatch can enter subclass code before subclass initialization has completed. The call may observe defaults instead of established invariants. The repair is to stop exposing a partially built object, not to add a sleep.
Follow-up: does an abstract class enforce immutability? No. It can define a construction and method contract, but mutable references and exposed setters remain independent design choices.
Working program
import java.util.ArrayList;
import java.util.List;
public class ReferenceInterviewProbe {
static void replace(List<String> receipts) { receipts = new ArrayList<>(); }
static void append(List<String> receipts) { receipts.add("r-72"); }
public static void main(String[] args) {
final List<String> receipts = new ArrayList<>();
receipts.add("r-41");
replace(receipts);
append(receipts);
System.out.println(receipts);
System.out.println(receipts.size());
}
}Output
[r-41, r-72]
2Cost and design choices
The reassignment creates a temporary empty list but does not replace the caller’s reference. The append mutates the shared list. This explains behavior through ownership, without a claim that Java passes objects by reference.
A good answer includes the observable result and the rule that causes it. Exact byte sizes and speculative VM optimizations are unnecessary for this reference question.
Common Mistakes
- Do not say Java passes objects by reference.
- Do not equate final with deep immutability.
- Do not promise content equality from Object.equals.
Connect the contracts
Compare the boundary explained in Initialization boundaries with the assumptions made by this program.
