What is singleton class?

Answer Posted / ranganathkini

A Singleton is a class which at any given time has only one
instance and it does not allow more instances to be created.
Such classes do not have an accessible constructor, for example:

public class Singleton {
// class is automatically instantiated when the
// class is loaded
private static Singleton instance = new Singleton()

// constructor is made inaccessible by declaring
// it private
private Singleton() { ... }

// Access to the single instance of the class is
// provided by a static accessor method
public static Singleton getInstance() {
// returns a reference of the private instance
return instance;

// rest of the class implementation

Is This Answer Correct ?    176 Yes 21 No

Post New Answer   View All Answers

Please Help Members By Posting Answers For Below Questions

What is Applet Stub Interface ?


What is the java project architecture?


how can i use a nonsynchronized hashtable?


hr interview how many minutes asking question


How to solve the problem of generating the unique hash keys with hash function?




Where can i get Latest SUN Certification Dumps and what are the Sun Certification Codes that are available, Im new to JAVA, so please gimme info as i need to write J2EE - Core Java Certification


EDS (Electronic Data Systems India Pvt Ltd) at Chennai on 16-12-2006.


os is developed in c no java is more secured then c na why dont the os developed is developed using java


Is it possible to declare abstract class as final?What happens if we do so?


what is the messsage u r going to get from an objectoriented programing?


what type of questions asked for barclays technologies pune please send urgent


4.1 Supply contracts (in the form of comments specifying pre- and post conditions) for the enqueue() method of the LinkedQueue class given in the Appendix. (2) 4.2 Let Thing be a class which is capable of cloning objects, and consider the code fragment: Thing thing1 = new Thing(); //(1) Thing thing2 = thing1; //(2) Thing thing3 = (Thing) thing1.clone(); //(3) Explain how the objects thing2 and thing3 differ from each other after execution of the statements. (


Why does java not allow multiple public classes in a java file ?


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example