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
Is it possible for yielded thread to get chance for its execution again ?
What is lastindexof in java?
How do I know if java is installed?
What is the purpose of using the java bean?
What do you understand by casting in java language?
Why isn’t there operator overloading?
can I implement my own start() method? : Java thread
How does sublist works in java?
Explain java coding standards for variables ?
Does constructor be static?
a thread is runnable, how does that work? : Java thread
What are advantages of exception handling in java?
When will we prefer to use set and list in java and why?
Can we overload final method in java?
Difference between a process and a program?