When i googled with "Subclassing Singleton class" string, many of the blogs said, we cannot extend the Singleton class as the constructor is private. But when i tried it in eclipse, i am able to subclass a singleton class. Would like to know whether can we subclass a singleton class technically?? If yes, will it not create many instances of Singleton class?
My singleton class
class SingletonClass {
private static SingletonClass singletonObject;
/** A private Constructor prevents any other class from instantiating. */
private SingletonClass() {
// Optional Code
}
public static synchronized SingletonClass getSingletonObject() {
if (singletonObject == null) {
singletonObject = new SingletonClass();
}
return singletonObject;
}
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
}