Under what circumstances would you define a constructor as private, and what does this achieve conceptually?
Last updated
A
privateconstructor stops outside code from callingnew, so the class controls how and whether instances are created.Common uses: Singleton, static factory methods (validation, caching, named creation), static-only utility classes, and bounded instance sets like enums.
Conceptually it encapsulates construction, enforcing creation rules at a single point.