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 do you know about java?
Is class forname reflection?
What is singletonlist in java?
What comes to mind when someone mentions a shallow copy in java?
What do you mean by byte code?
What is bifunction in java?
What is array pointers ?
What is api data?
Why do we need wrapper class?
What is double data type?
Can a class have a static inner class?
what is recursion in java
What is a wrapper method?
Why are the objects immutable in java?
write a program that list all permutations of ABCDEF in which A appears before B?