Skip to content
Sharp

Object-oriented programming · interview question

What is one common practice to achieve immutability in Java classes?

Multiple choiceEasychapter-3-curatedpremiumoopimmutability-basics
Choose one answer
Answer and explanation

Correct answer

C. Declare all fields as final and private.

Why

Declaring fields as final and private ensures they cannot be modified after the object is constructed, which is a foundational practice for achieving immutability.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →