Why private constructors? What's the use? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why private constructors? What's the use?

30th Apr 2021, 7:48 AM
kreddyt
kreddyt - avatar
2 Answers
+ 3
Yes, you can a have private constructor. This is a common design pattern practice most often used with a Singleton class. It will then usually be accessed from a public static method.
30th Apr 2021, 8:44 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
I don't think constructors can be private
30th Apr 2021, 7:50 AM
kris
kris - avatar