What is singleton class?
Answer Posted / srinivas pentakota
A singleton is an class that can be instantiated once, and
only once. This is a fairly unique property, but useful in a
wide range of object designs. Creating an implementation of
the singleton pattern is fairly straightforward - simple
block off access to all constructors, provide a static
method for getting an instance of the singleton, and prevent
cloning.
public class SingletonObject
{
private SingletonObject()
{
// no code req'd
}
public static SingletonObject getSingletonObject()
{
if (ref == null)
// it's ok, we can call this constructor
ref = new SingletonObject();
return ref;
}
private static SingletonObject ref;
}
| Is This Answer Correct ? | 27 Yes | 14 No |
Post New Answer View All Answers
How dead lock situation occurs in java and how you can identify it?
How many types of the indexof method are there for strings?
FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?
Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?
What is the use of object and class classes?
Will set allow duplicates in java?
Can an interface have a class?
What is primitive array?
Java Compiler is stored in JDK, JRE or JVM?
What is the purpose of encapsulation?
How much ram can a 64 bit processor theoretically?
What is a loop java?
What is considered an anti pattern?
What is an array length?
What is the purpose of an interface?