Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Which variables are stored in heap?

1034


What is udp in java?

990


When will you define a method as static in Java?

1064


What class allows you to read objects directly from a stream in java programming?

1082


What is use of map in java?

1016


Is assembly language a low level language?

966


What is queue in java?

1157


How to overcome the exception object reference not set to an instance of object?

1153


How can I become a good programmer?

987


Is a char always 1 byte?

994


Differentiate between run time error and syntax error.

1145


which pattern is default in scanner package?

2240


Will the jvm load the package twice at runtime?

1102


explain the difference between jdk and jvm?

1002


Why string is called as immutable?

961