Skip to content
Sign in
Computer

What is the function of a constructor in Java?

Tap an option to check the answer. You can also press A–D.

Show answer

Correct answer: B) It initializes an object when it is created.

A constructor is automatically called when an object is instantiated, setting initial values. Unlike regular methods, it has the same name as the class and does not have a return type.
Explanation
A constructor is automatically called when an object is instantiated, setting initial values. Unlike regular methods, it has the same name as the class and does not have a return type.