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 are the differences between forwarding () method and sendredirect() methods?
Explain a situation where finally block will not be executed?
what is the difference between future and callable interface in java?
Can you declare a private method as static?
Highest level event class of the event-delegation model?
How do I enable java in safari?
What is the difference between yielding and sleeping in java programming?
What is procedure writing?
What is an error in java?
Can you give names of Container classes?
What is use of map in java?
How to sort numbers in java without array?
Explain the difference between treeset and treemap in java?
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
What is meant by string is immutable?