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


Please Help Members By Posting Answers For Below Questions

What are the different types of inheritance in java?

503


What is contract between hashcode and equal method?

546


Which data type is class in java?

526


What is 32 bit float?

528


What is the difference between C++ and Java and your preferences?

590






What does the “static” keyword mean?

564


What’s the difference between unit, integration and functional testing?

591


How many bytes are there?

515


What are the steps in the jdbc connection?

550


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

3161


How many types of memory areas are allocated by jvm?

535


What is a java developer salary?

518


Is it possible to use Semaphore/ Mutex in an Interrupt Handler?

503


How to use string tokenizer class.

597


Which is the best sorting technique in java?

499