Skip to content
Sharp

Object-oriented programming · interview question

In Java, what is the purpose of a constructor?

Multiple choiceEasychapter-2-curatedpremiumoopinstance-methods
Choose one answer
Answer and explanation

Correct answer

A. To initialize a new object.

Why

A constructor is used to initialize a new object in Java. It sets the initial state of the object by assigning values to its fields.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →