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 nested loop? What is dangling else condition in it?
In how many ways we can do exception handling in java?
What is a java lambda expression?
What is a method in java?
How will you load a specific locale?
What is the equal sign?
What do you mean by aggregation?
What are the types of relation?
What is the difference between checked exception and unchecked exception?
List some features of the abstract class.
What is class forname?
What is command line used for?
What is difference between next () and nextline () in java?
What are the advantages of autoboxing?
What steps are taken when the OS shifts from one-thread execution to another?