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 do you understand by the term string pool?
Compare overloading and overriding?
What are annotations in java?
Explain about class in java?
How do you use compareto method?
What is a predicate method?
Is it possible to instantiate the abstract class?
What is string substring?
What is thread count in java?
What is a arraylist in java?
Difference between a class and an object?
Write a program to calculate factorial in java?
What is toarray method in java?
What is the difference between length and size in java?
What is the purpose of nested class in java?