Skip to content
Sharp

Object-oriented programming · interview question

How would you explain a constructor's role regarding class fields in an interview?

Multiple choiceEasychapter-2-curatedpremiumoopconstructors
Choose one answer
Answer and explanation

Correct answer

C. To initialize fields when an object is created.

Why

A constructor's primary role is to initialize fields of a class when a new object is created. This ensures that the object starts with a valid state.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →