Skip to content
Sharp

Object-oriented programming · interview question

In Java, what role do constructor parameters play in ensuring immutability for a class?

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

Correct answer

C. They allow initialization of final fields.

Why

Constructor parameters allow for the initialization of final fields, which is crucial for immutability. Once a field is initialized through the constructor, its state cannot change, thus maintaining the immutability of the class.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →