Computer Science, asked by stylemylo9970, 1 year ago

What is a constructor in Java?

Answers

Answered by amol1372
0

The use of private constructor is to serve singleton classes. A singleton class is one which limits the number of objects creation to one. Using private constructor we can ensure that no more than one object can be created at a time. By providing a private constructor you prevent class instances from being created in any place other than this very class. We will see in the below example how to use private constructor for limiting the number of objects for a singleton class.


amol1372: please mark me brainlist
Answered by amitaagarwal4827
0

Answer:

constructors are used in initialise the object state like methods a constructor also contains a collection of statements that are executed at time of object creation.

Similar questions