Question
In terms of inheritance, what is the effect of keeping a constructor private?
Solution
If the programmer does not provide a constructor for a class, the system will always provide a default, public no-argument constructor.
To disable this default constructor, simply add a private no-argument constructor to the class.
Two categories of usage:
- Object construction is entirely forbidden
- class offers only static members (sometimes called utility class)
- Object construction is private only
- a class needs to prevent the caller from creating objects, like Singleton