Skip to content
Sharp

Core Java · interview question

How would you explain a common method to ensure an object's immutability in a Java interview?

Multiple choiceMediumchapter-3-curatedpremiumcore-javacode-reading-and-state-safety
Choose one answer
Answer and explanation

Correct answer

C. Making all fields private and final

Why

To ensure immutability, all fields should be private and final, preventing modification after the object is constructed.

Test yourself on Core Java

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

Start free test
All Core Java questions →