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
Explain about object oriented programming and its features?
What is fundamental datatype?
define polymorphism in java
What is the memory leak in java?
How we can generate random numbers in java?
What isan abstract class and when do you use it?
What methods are used to get and set the text label displayed by a button object?
What is the use of default method in interface in java?
Is void a data type?
Java is pass by value or pass by reference? Explain
Explain yield() method in thread class ?
How do you trim a space in java?
What is string builder?
is it possible to instantiate the math class?
What does indexof return in java?