Why do we need a private constructor?

后端 未结 10 570
一整个雨季
一整个雨季 2020-11-30 18:20

If a class has a private constructor then it can\'t be instantiated. So, if I don\'t want my class to be instantiated and still use it, then I can make it static.

Wh

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 18:33

    If the class ONLY has private constructors, it cannot be instantiated from outside.

    You can also have private constructors and public constructors with different signatures.

提交回复
热议问题