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
how to write a server program and sending the mails to the server using smtp protocol please help me
What is the difference between overriding and overloading in OOPS.
What is lossy conversion in java?
What does it mean that strings are immutable?
Is string a class in java?
What is a locale?
What an i/o filter?
What does java final mean?
What are benefits of java?
What is difference between throw and throws ?
Write a function to find out longest palindrome in a given string?
What happens if an exception is not handled in a program?
How do you define a method?
How do you define a singleton class?
Explain about interthread communication and how it takes place in java?