What is the constructor?

DWQA QuestionsCategory: JavaWhat is the constructor?
Editor Staff asked 11 months ago

What is the constructor?

1 Answers
Editor Staff answered 11 months ago

The constructor can be defined as the special type of method that is used to initialize the state of an object. It is invoked when the class is instantiated, and the memory is allocated for
the object. Every time, an object is created using the new keyword, the default constructor of the class is called. The name of the constructor must be similar to the class name. The
constructor must not have an explicit return type.