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 e in java?
What is the difference between super class & sub class?
What do you mean by inner class in java? Explain
What is java literals?
What is the platform?
What is ph and buffers?
What is the name of the java compiler?
What is byte code and why is it important to java’s use for internet programming?
does java support pointers?
Write a program to print the pattern given below
Explain jvm, jre, and jdk?
how to deploy tomcatserver to weblogic server? write d following steps?
What is the use of toarray () in java?
What is mysql driver class name?
How to create a custom exception?