What is immutable class? how to make a Class explicitly
"Immutable"?Wap to make a class explicitly immutable.
Answer Posted / rv.nandakishore
I think u know... String is not a data type.. it is a
class...right..
By default the String class is a immutable class. That means
once we instantiate the object or assigning the value to
String is immutable. Once we can assign / instantiate the
String class we can't change in the future....
class StringDemo
{
public static void main(String[] args)
{
String s1="Nanda";
String s2="Kishore";
String s3=new String("Nanda Kishore");
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
}
}
U try any changes anything and print s1,s2 & s3.... If
changes then it is not immutable. If not it is immutable.
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Which method cannot be overridden in java?
What are the differences between string and stringbuffer?
Explain the features of interfaces in java?
What is the use of java?
What is the difference between reader/writer and inputstream/output stream?
Why we used break and continue statement in java?
Why are the objects immutable in java?
How can a gui component handle its own events in java programming?
What is continuity of a function?
Difference between method overloading and overriding.
What is array command?
What is the difference between JDK and JVM?
Program to Find the second largest element in an array.
What is the benefit of inner / nested classes ?
How can we find the actual size of an object on the heap?