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
What is difference between path and classpath?
Difference between a class and an object?
Can I declare a class as private?
What is the generic function?
How to use string tokenizer class.
What is the parse method in java?
Is java programming easy?
What checkbox method allows you to tell if a checkbox is checked?
What is the advantage of preparedstatement over statement?
What are the difference between string, string builder, and string buffer in java?
What are methods?
Who is the owner of java?
Why do we need singleton class?
What is wrapper class example?
What are alternatives to java serialization?