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 are the types of relation?
What is oop in java?
How do you reverse a string in java?
What about static nested classes in java?
Can a class have an interface?
What do u mean by variable?
What is output buffer?
What are different types of arrays?
What is the difference between Java1.4 and Java1.5
Why are arrays useful in java?
What is difference between adapter class and listener?
How can we create objects if we make the constructor private ?
What is the difference between a constructor and a method?
What is the difference between a window and a frame in java programming?
What is the maximum size of list in java?