Skip to content
Sharp

Object-oriented programming · interview question

Why does a constructor in a Java class matter in practice?

Multiple choiceMediumchapter-2-curatedpremiumoopfields-and-state
Choose one answer
Answer and explanation

Correct answer

C. To initialize the state of an object

Why

A constructor in Java is a special method that is called when an object is instantiated. Its primary purpose is to initialize the object's fields with specific values.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →