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
What is the biggest integer?
What is the full meaning of java?
What is a lightweight component?
Write a program to search a number in the given list of numbers.
What is the difference between multiple processes and multiple threads?
What do you mean by thread safe?
Is list ordered in java?
Is arraylist ordered?
What are the different approaches to implement a function to generate a random number?
How is a structure different from array ?
What are the types of methods in java?
What is the reason behind using constructors and destructors?
What is a null point?
What is a conditional statement explain with example?
When should I use singleton?