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
Can arraylist contain null values?
What are the super most classes for all the streams?
What is the size of int in 64-bit jvm?
What are the 5 types of research methods?
Is it possible to instantiate the abstract class?
What programs use java?
How do you remove an object from an arraylist in java?
How do you declare an empty string?
What is a conditional equation?
Explain when noclassdeffounderror will be raised ?
Which is fastest collection in java?
23. Storage space in java is of the form Stack Queue Heap List 24. What is java code embedded in a web page known as Applets Servlets scriptlets snippets 25. Which of the following attributes are compulsory with an
Explain constructors and types of constructors in java.
Can we store variables in local blocks?
How do you implement singleton class?