What is the constructor?

Category: JavaWhat is the constructor?
Editor">Editor Staff asked 2 years ago

What is the constructor?

1 Answers
Editor">Editor Staff answered 2 years 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.