--
The private constructors are used in the following situation:
The private constructors are used in the following situation:
- When you implement
singletons
orfactory
design pattern. - Do not want people to instantiate your class directly. e.g., new MyObject();. For example, all of your method and fields are static, you may need to add a private default constructor (if you do not have it, compiler will add one for you that is not what you want). Such way can enforce that people can not accidently use "new".
Comments
Post a Comment