Skip to content
Sharp

Software Architecture · interview question

When implementing the Builder pattern, what is an effective way to ensure that the constructed object is immutable?

Multiple choiceHardchapter-13-curatedpremiumsoftware-architecturebuilder-pattern
Choose one answer
Answer and explanation

Correct answer

B. Use private final fields and only modify them in the constructor.

Why

Immutability is achieved by using private final fields and setting them only in the constructor, ensuring that they cannot be changed after the object is constructed. This approach prevents modification of the object's state after creation.

Test yourself on Software Architecture

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

Start free test
All Software Architecture questions →