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
What are the different types of inheritance in java?
What is contract between hashcode and equal method?
Which data type is class in java?
What is 32 bit float?
What is the difference between C++ and Java and your preferences?
What does the “static” keyword mean?
What’s the difference between unit, integration and functional testing?
How many bytes are there?
What are the steps in the jdbc connection?
which is advanced deep technology in java launched by the sun microsystem??? The answer is very logical If u need correct answer mail me at priya_gupta@gmail.com
How many types of memory areas are allocated by jvm?
What is a java developer salary?
Is it possible to use Semaphore/ Mutex in an Interrupt Handler?
How to use string tokenizer class.
Which is the best sorting technique in java?