Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers | ||||
| ||||
Ans. Java provides a default constructor ( no argument ) if no constructor is provided by the programmer. Java makes a check during pre compilation if there is any constructor provided by the programmer. If any constructor is provided, Java understands that programmer has provided all the mechanism for initialization and construction of the object and may not even intend to create objects by calling a no argument constructor. For example - One may like to have objects created with self defined state otherwise restrict its creation. We make the constructor private if we want to make a class singleton as we would like to restrict creation of new objects using new operator and default constructor. Similar could be the situation wherein we would like to construct objects in a particular manner only. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  default constructor expert | ||||
Related Questions | ||||
Why Java provides default constructor ? | ||||
What is a Default Constructor ? | ||||
Will Compiler creates a default no argument constructor if we specify only multi argument constructor ? | ||||
Difference between Class#getInstance() and new operator ? | ||||
Can we create an object if a Class doesn't have any constructor ( not even the default provided by constructor ) ? | ||||
Does every class needs to have one non parameterized constructor ? | ||||
Variable of the boolean type is automatically initialized as? | ||||
In a case where there are no instance variables what does the default constructor initialize? | ||||
Is it mandatory to have a default constructor ? | ||||