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
Why synchronization is important in java?
Difference between operator overloading and function overloading
Explain the importance of join() method in thread class?
Explain OOPs concept.
What do you mean by composition in java?
What is arrays aslist in java?
What is collection class in java? List down its methods and interfaces.
Explain the available thread states in a high-level?
What are multiple inheritances?
Why there is no call by reference in java?
what is the difference between yielding and sleeping? : Java thread
Whats the difference between notify() and notifyall()?
What is meant by bytecode?
What is flag in java?
How do you start a new line in java?