+ 1

Why a constructor is always declare as the public? But not as private or protected.

26th Feb 2017, 5:13 PM
Abhishek Satpathy
Abhishek Satpathy - avatar
3 Réponses
+ 3
There are some design patterns that use access restriction on constructors like Singleton and Abstract Factory.
26th Feb 2017, 8:50 PM
1of3
1of3 - avatar
+ 2
You can declare the private constructor. But you can't create the object of class because the constructor cannot be called outside the class. And the compiler will not allow you to create a protected constructor
26th Feb 2017, 6:00 PM
SUPER_S
SUPER_S - avatar
0
becoz constructor is called when the object is declared ,object is declared outside the class ,outside the class we can only access the public member function of the class ...
24th Mar 2017, 6:30 AM
Manas Mishra
Manas Mishra - avatar