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 Singleton

Answer Posted / hardeep thakur

Here is code to implement the singleton

public class SingletonClass {
private static SingletonClass singleObj ;
private SingletonClass(){}

public static synchronized SingletonClass getInstance()
{
if(singleObj ==null){
singleObj = new SingletonClass();
}
return singleObj;
}

public Object clone() throws CloneNotSupportedException
{
throw new CloneNotSupportedException();
}

}

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is numeric function?

995


Can we have multiple classes in single file ?

1064


Name and explain the types of ways which are used to pass arguments in any function in java.

1070


why Java does not support multiple inheritances?

1146


Does chrome use java?

953


how are methods defined?

1043


What is the importance of main method in Java?

1053


What is thread pool? How can we create thread pool in java?

1058


What are encapsulation, inheritance and polymorphism?

999


Where is stringbuffer stored?

970


What is a return in java?

1024


What is a default constraint?

1063


Explain the difference between extends thread vs implements runnable in java?

1124


What is the difference between sleep and wait in java?

954


Can we override constructor in java?

1084