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
Can we write any code after throw statement?
How do you include a string in java?
What is a hashmap used for?
Is it possible for a yielded thread to get chance for its execution again?
Can we define package statement after import statement in java?
What are checked exceptions?
Can you call a method in a method?
What is finalize method?
How does arraylist work in java?
What is the finalize method do?
What is a class instance variable?
What is arraylist e in java?
What are the basic control structures?
What do you understand by a Static Variable?
What do you mean by compiler?