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 is meant by javabeans?
When do we use synchronized methods in java?
What is string english?
How many types of design patterns are there?
What are accessor methods in java?
How do you check if a string is lexicographically in java?
Do you know how to reverse string in java?
What happens if we don’t override run method ?
What is a java object and java application?
What does exp mean in math?
Is cout buffered?
How do you do math powers in java?
How to find the largest value from the given array.
What is a qms manual?
Explain public static void main(string args[]) in java.