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 you create an object of an abstract class?
What is the program compilation process?
What is number data type?
What is a locale?
What is the difference between an interface and an abstract class?
what is the difference between a threads start() and run() methods? : Java thread
What is a static method in java?
what do you mean by java annotations?
What is a line break example?
What is called module?
Can long be null in java?
What is passing by reference in java?
How to instantiate member inner class?
What is a cup of java?
What is static synchronization?