Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton Object

 
Nimmy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What�s the difference between a singleton class and a static class?

If the answer is static class is one approach to make a class �Singleton� I have one doubt.

If the constructor is public I can create more than one instance then how does it work like a singleton?
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think this is what you are looking for.

please go through it. that should solve most of your queries.
 
Sivalingan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please go thou the following link for more details about design pattenrs

http://www.javacamp.org/designPattern/index.html

www.allapplabs.com
 
Edwin Keeton
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were trying to implement Singleton with a "static class" (meaning all members of the class are static), you would not use a public constructor. You would implement an unused private constructor so there would be no public default constructor. Ane while you were at it you would make the class final to prevent a subclass creating an instance.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic