Answer Posted / shaik baji
Singleton Example:
==================
public class Singleton
{
private static Singleton singleton;
private Singleton()
{
}
public static Singleton getInstance()
{
if(singleton==null)
{
singleton = new Singleton();
return singleton;
}
else
{
return singleton;
}
}
}
Accessing Singleton instance
============================
public class STDemo
{
public static void main(String[] args)
{
Singleton obj1= Singleton.getInstance();
System.out.println(obj1.hashCode());
Singleton obj2= Singleton.getInstance();
System.out.println(obj2.hashCode());
Singleton obj3= Singleton.getInstance();
System.out.println(obj3.hashCode());
}
}
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is nan in java?
What is the meaning of nullable?
What is meant by flickering?
What is a nested class?
Which programming language is best in future?
Why string is not thread safe?
What are the different data types in java?
What is difference between this and super keyword?
What will happen to the exception object after exception handling?
What is the use of put method?
What is meant by JVM? Is JVM platform independent or not?
How do you declare an array in java?
What does @override mean?
What is boolean law?
How to create a thread in java?