Search code examples
javaconstructorprivate-methods

When is it useful to use a private constructor?


Possible Duplicate:
What is the use of making constructor private in a class?

When is it useful to use a private constructor? What about a protected one?


Solution

  • it's useful when you want to prevent external instantiation of an object, e.g. static factory classes, singletons, and etc.