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 methods in java?
Is java jre still free?
How many ways can an argument be passed to a subroutine and explain them?
What is the final field modifier?
What is re-factoring in software?
Name component subclasses that support painting in java programming?
What is broken and continue statement?
What is time complexity java?
What is the impact of declaring a method as final?
Why lambda expression is used in java?
Which data type is class in java?
What is difference between fail-fast and fail-safe?
Is an array a vector?
Write a program to reverse a number in java?
Can a lock be acquired on a class in java programming?