What is the function of a constructor in Java?

  • AIt is used to call other methods.
  • BIt initializes an object when it is created.
  • CIt is used to delete objects.
  • DNone of these.
Show answerHide answer

Correct answer B

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.