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
How do you add an element to a set in java?
What are the legal operands of the instanceof operator?
Can we catch more than one exception in single catch block?
Explain the scope of a variable.
Is double bigger than float?
Can constructor return value?
List types of storage classes in java?
Assume a thread has lock on it, calling sleep() method on that thread will release the lock?
What is final int?
Explain about features of local inner class?
Differentiate between stringbuffer and string?
What is difference between == equals () and compareto () method?
What is jar?
Can we have a method name same as class name in java?
How do you initialize an arraylist in java?