+ 3

How to use private constructor ?

I still can't get hold of it, if private constructor cannot be accessed from outside the class, then what is the use of having private constructor !

2nd Mar 2017, 5:40 AM
Preet Patel
Preet Patel - avatar
4 Réponses
+ 8
You use it, if you don't want to be the class instantiated from another class. Search for Singleton pattern on Google. Rarely used.
2nd Mar 2017, 6:00 AM
Tashi N
Tashi N - avatar
+ 1
Thanks @Tashi N
2nd Mar 2017, 6:01 AM
Preet Patel
Preet Patel - avatar
0
you can create object inside the same class
2nd Mar 2017, 7:39 PM
Wazed Ali Gazi
Wazed Ali Gazi - avatar
- 1
None.
2nd Mar 2017, 5:53 AM
Seckar
Seckar - avatar