Google News
logo
Java Constructor - Interview Questions
What is a Java Constructor?
Java constructor is a unique method that initializes the objects, which is called when an instance of the class is created. The memory for the object is allocated when we call the constructor.
 
Basically, a constructor is a block of code. When we create an object of the class using the new() keyword, at least one constructor is called, and it initializes the objects and allocates memory to them.
 
If we do not specify any constructor, it will call the default constructor of the class. However, it is not necessary to specify an explicit constructor because the Java compiler provides a default constructor for every Java class.
Advertisement