Possible Duplicate:
Difference between static class and singleton pattern?
I was wondering,
Would a class such as Java’s Math class, where all methods are static be considered a singleton? Or does a singleton have to have an instance, eg: Math.getInstance().abs(...) to qualify as a singleton?
Thanks
Having just static methods in a class does not qualify it being a
Singleton, as you can still make as many instances of that class, if you have apublic constructorin it.For a class to qualify as
Singleton, it should haveprivate constructor, so that it can’t be instantiated from outside the class, and have astatic factorythat returns thesame instanceeverytime invoked.If you really mean
static class, then first of all, you can’t have yourtop-levelclass asstatic. You can only havestatic nested class, in which case you don’t need to create any instance of that class, but you can and you can create multiple instances and hence it as notSingleton.Also, the class you mentioned –
java.lang.Math, is not a static class. You should see the documentation of that.