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 var keyword ?
What is garbage collection? What is the process that is responsible for doing that in java?
What is an example of a keyword?
Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?
Do I need java on my pc?
What is the difference between yield() and sleep()?
Explain the difference between private, public, package and protected in java?
Explain exception chaining in java?
Why we do exception handling in java and how many types of exceptions are there?
Class c implements interface I containing method m1 and m2 declarations. Class c has provided implementation for method m2. Can I create an object of class c?
What is the difference between normal report & matrix report?
What is gc()?
What are the five major types of reference sources?
Can a static method be overridden in java?
What is a marker interface?