can any one send me the example program of immutable class?
Answer Posted / jinxuan
public class SingletonTest
{
public static void main(String[] args)
{
Singleton singleton = Singleton.getInstance();
Singleton singleton1 = Singleton.getInstance();
System.out.println(singleton == singleton1);
}
}
class Singleton
{
private static Singleton singleton = new Singleton();
private Singleton()
{
}
public static Singleton getInstance()
{
return singleton;
}
}
it means whenerver you new a Object,it returns the same
object address, i'ts Singleton Pattern. so your object is
immutable class
| Is This Answer Correct ? | 0 Yes | 3 No |
Post New Answer View All Answers
What is the purpose of garbage collection in java?
Name the components that are termed to be Heavy-weight component but available in Light-weight components?
What is the difference between a vector & an array list?
How do you check whether the list is empty or not in java?
Why synchronization is important in java?
What is a dot notation?
Explain garbage collection in java?
Difference between overriding and overloading in java?
Which of the following is not an isolation level in the JDBC
Explain the difference between a Thread and a Process.
Why hashset is used in java?
What is the size of a string in java?
What is exception in java?
What is replacefirst in java?
What is namespace in java?