Hello friends ... I have a doubt related to access modifier of constructor of singleton class
class Singleton{
public static Singleton Instance() {
if (_instance == null)
_instance = new Singleton();
return _instance;
}
protected Singleton() {}
private static Singleton _instance = null;
}
I know that if we use protected constructor other classes can create Singleton instance using new Singleton();
But in many tutorials available on internet like on wikipedia
http://en.wikipedia.org/wiki/Singleton_pattern
protected constructor is used with comment // Protected constructor is sufficient to suppress unauthorized calls to the constructor
Please clear my doubt why they have used protected constructor.
Is it correct to use protected constructor in a Singleton class?
Thanks,
Anuj