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


Please Help Members By Posting Answers For Below Questions

Which method cannot be overridden in java?

602


What are the differences between string and stringbuffer?

591


Explain the features of interfaces in java?

558


What is the use of java?

528


What is the difference between reader/writer and inputstream/output stream?

559






Why we used break and continue statement in java?

561


Why are the objects immutable in java?

546


How can a gui component handle its own events in java programming?

536


What is continuity of a function?

523


Difference between method overloading and overriding.

582


What is array command?

561


What is the difference between JDK and JVM?

635


Program to Find the second largest element in an array.

591


What is the benefit of inner / nested classes ?

527


How can we find the actual size of an object on the heap?

806