Computer
What is the function of a constructor in Java?
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.