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 numeric function?
Can we have multiple classes in single file ?
Name and explain the types of ways which are used to pass arguments in any function in java.
why Java does not support multiple inheritances?
Does chrome use java?
how are methods defined?
What is the importance of main method in Java?
What is thread pool? How can we create thread pool in java?
What are encapsulation, inheritance and polymorphism?
Where is stringbuffer stored?
What is a return in java?
What is a default constraint?
Explain the difference between extends thread vs implements runnable in java?
What is the difference between sleep and wait in java?
Can we override constructor in java?