emma smith wrote:but it is possible to subclass it and define a new public constructor to instantiate another Singleton
That's not true! In this code snippet, class
Def fails to compile because the constructor of class
Abc is not visible (because it's
private).
emma smith wrote:how can i have only one instance of singleton that any subclass can't be able to instantiate another?
If you don't want subclasses to be created, just make the
Singleton class
finalSince
Java 5.0 you could use an
enum to represent the singleton design
pattern as well
And you don't have to worry about subclassing, because that's not allowed with an
enum.
Hope it helps!
Kind regards,
Roel