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

Give an example of call be reference significance.

1081


How many JVMs can run on a single machine and what is the meaning of Just-In-Time (JIT) compiler?

1546


Why 1 is not a prime number?

1076


I want to control database connections in my program and want that only one thread should be able to make database connection at a time. How can I implement this logic?

1141


Does apple use java?

1000


How do you override a variable in java?

1236


How do you declare an array that will hold more than 64KB of data?

1387


when should you use stringbuilder class in a program?

1028


Why parsing is done?

1028


Why singleton class is used in java?

1195


What is difference between == equals () and compareto () method?

1096


What is externalizable?

1116


What is static keyword in java?

1057


How to sort an array from smallest to largest java?

1036


Which is better ascii or unicode?

1042