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 ?

1113


What is the java project architecture?

973


how can i use a nonsynchronized hashtable?

1215


hr interview how many minutes asking question

793


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

631


Realized?

754


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

577


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

7424


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

2409


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

100


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

759


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

4196


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. (

567


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

1874


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

1218