String is a immutable objects . it means that string does
not change...........
But it will be chang.........
{
String s="kapil";
String s1="raj";
String s=s1;
then print(.......)
The String has been changed ..
how it is possible and why its called immutable objects
Answer Posted / jay
First the JVM will creates two objects s and s1 separately
when s=s1 is done JVM creates the new object and stores the
string "raj" in that object.But it does not modify the
contents of string s.After creating the new object the
reference of s is adjusted to refer the new object.
The point we observe here is that the contents of of the
string s is are not modified.This is the reason Strings are
called Immutable.The old object that contains "kapil" has
lost its reference.so it is called "Unreferenced object" the
garbage collector will removes it from memorey.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
how are methods defined?
What kind of variables can a class consist?
What do you mean by object?
What is meant by tab pans?
Explain the difference between extends thread vs implements runnable in java?
What happens when I use / and % with a negative numerator?
Which software is used for java programming?
List two java ide’s?
What is difference between overloading and overriding in java?
What are different exception types exceptions available in java ?
Is char a method in java?
Which keyword specify that a variable is effectively final ?
What is mnemonic in assembly language?
Does treeset use compareto?
What are classloaders?