Home > Software > Java > Core-Java
Interview Questions   Tutorials   Discussions   Programs   

Core-Java - What is singleton pattern?

asked marvit September 17, 2014 07:04 AM  

What is singleton pattern?


1 Answers

answered By Madhumathi   0  

The Singleton's purpose is to control object creation, limiting the number of obejcts to one only. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields. Singletons often control access to resources such as database connections or sockets.

We can make constructor as private. So that We can not create an object outside of the class. This property is useful to create singleton class in java. Singleton pattern helps us to keep only one instance of a class at any time. The purpose of singleton is to control object creation by keeping private constructor.

   add comment

Your answer

Join with account you already have



Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!