Select from following answers:- The constructor can only be accessed from static factory method inside the class itself
- The Class cannot be inherited
- It prevents creating copys of the class
- All

- All Above
Private Constructor is a special instance constructor used in class that contains static memory only.
The primary use of a private constructor is not to allow to create class instance when there are no instance fields or methods, or when a method is called to obtain an instance of a class. Some probable use cases are
a) The constructor can only be accessed from static factory method inside the class itself
e.g Singleton Class (where not more than one instance of the class exists in the program.)
b) Preventing creating copy of the class (i.e. copy constructor)
c) Class cannot be inherited
Show Correct Answer
Asked In: Many Interviews |
Alert Moderator