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 are synchronized blocks in java?
Write a program based on Java script program.
What is the vector class in java programming?
What is scope of a variable?
Is java based on c?
How is a structure different from array ?
How do you access command-line arguments within the code?
What are the library functions in java?
if u open login & logout ,how can udisplay the timelogin & logout members ?
How are the elements of a gridbaglayout organized?
Can we change the value of static variable?
What happens when I use / and % with a negative numerator?
Where to store local variables?
what is thread in Java ?
What is the impact of declaring a method as final?