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 a static class can contains?
Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?
What is singletonlist in java?
How can you say java is object oriented?
What is the output of the below java program?
Can we extend singleton class in java?
Can we split string with in java?
What is this keyword used for?
why Java does not support multiple inheritances?
What is <> used for in java?
What is the difference between == and === javascript?
What is lexicographically smallest string?
What is a static class in java?
Explain about object oriented programming and its features?
Can we declare a class as abstract without having any abstract method?