+ 6

Why to mark constructor as private in Java ?

I know the constructor in Java can be marked as private, but I don't know why to do that ? What is the purpose of private constructor ? Please provide an example.

29th Aug 2017, 12:36 PM
Corey
Corey - avatar
1 Antwort
+ 9
Example where you could use a private constructor: Singleton pattern. https://www.sololearn.com/discuss/129670/?ref=app https://www.sololearn.com/discuss/380564/?ref=app and many more threads.
29th Aug 2017, 12:39 PM
Tashi N
Tashi N - avatar