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
What is a hashmap used for?
Define how can we find the actual size of an object on the heap?
What is the final method?
How do you remove an element from an arraylist in java?
Explain java coding standards for constants?
What is a dynamic array in java?
How the metacharacters are different from the ordinary characters?
What is difference between c++ and java ?
Write a program to find the whether a number is an Armstrong number or not?
What are the differences between heap and stack memory?
Define immutable object?
Can we define private and protected modifiers for the members in interfaces?
What is parsing a string?
What are the 4 types of research methods?
How do I get 64 bit java?