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
What sorting algorithm does javascript use?
What does function identity () do?
What are the two categories of data types in the java programming language?
Can we override the static methods?
What is the maximum size of hashmap in java?
What is a default constructor and also define copy contrucyor?
What is valid keyword in java?
a thread is runnable, how does that work? : Java thread
How does a for loop work java?
What are pass by reference and pass by value?
Can we serialize static variables in java?
What is thread life cycle?
Explain when noclassdeffounderror will be raised ?
How does a for loop work?
What is an argument in java?