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
Can we have a try block without catch block?
Is 0 an irrational number?
What is the different between get and post?
Explain what pure virtual function is?
What do you understand by looping in java? Explain the different types of loops.
What are the types of web technologies?
What do you mean by formatting?
How to perform merge sort in java?
What state is a thread in when it is executing?
How many types of array are there?
What is general methodology?
What about static nested classes in java?
Say any two properties in beans?
State one difference between a template class and class template.
What is OOP Language?