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 transient keyword?
What is double checked locking in singleton?
How can we achieve thread safety in java?
What is the relationship difference the canvas class and the graphics class?
How do you convert an int to a string in java?
Can java object be locked down for exclusive use by a given thread?
Which is faster set or list in java?
What is the constructor?
What is the set interface in java programming?
What does || || mean in math?
What is the difference between a scrollbar and a scrollpane?
Which is best ide for java?
Where is core java used?
What does g mean in regex?
What about main thread in java?