Yes, you can declare a constructor as private. Once a constructor is declared private, you cannot create an object of a class. We use private constructors in the Singleton Design Patterns.
Rules for private constructors:
1. The private constructor does not allow object creation outside the class and a class to be subclassed.
2. We can use a private constructor when all the methods are static.
3. If we extend a class containing a private constructor, then a compile-time error will occur.
Posted Date:- 2021-09-30 00:33:19