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...

How to implement or use the singleton class in java?

Answer Posted / aashish r. wadhokar

Singleton is a design pattern as well as class.
when we define singleton class it means we can have only one
object of that class.
We cant create multiple objects of that class.
In singleton class, constructor is always private.

eg:
public class Singleton
{
private static Singleton singletonObject = null;
private Singleton()
{
System.out.println("Singleton object created!!!");
}
public static Singleton CreateInstance()
{
if(singletonObject == null)
{
singletonObject = new Singleton();
}
return singletonObject;
}

Now we can get object as:
Singleton ref = null;

ref = Singleton.CreateInstance();

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi Friends, i have searched in google but not clear. can you give bank example with synchronized keyword

2032


What are the different types of classes implemented in the set interfaces? : java collections

1038


What is the enumerator of the java collection framework? : java collections

1017


What is an algorithm in java collection framework? : java collections

1034


Which interface does java.util.hashtable implement?

1178


What are the different types of ways where you can iterate over a list? : java collections

1010


please mail me the interview question based on java/j2ee

1929


In hyderabad, which s/w training center is best for java, other than corejava what r the new tools to learn in java,which tool is best & have current requirement,pls give me information about java to learn ?

2146


what is mean by hasing and maping in java platform and advantage?

2356


What are the types of java collections? : java collections

1026


What is deque in the java collections framework? : java collections

1051


What are the interfaces in java collections? : java collections

1127


What are the classes in the java collection framework? : java collections

1024


What is the use of the list interface in the java collection? : java collections

1006


What are the main classes of the list interfaces? : java collections

1014