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 / christine
Immutable means if you apply any methods to a String, it
would not affect the original String you created.
For eg,
String s = "test";
s.concat(" two");
System.out.println(s);
The output is still "test" and not "test two";
Java pass by reference. If you use = to assign the string
to another string, then the reference would change.
Therefore your example changes the string.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Why does java doesnt suuport unsigned values?
What is the difference between array and array list in java?
What happens if we don’t define serial version uid?
What are variable arguments or varargs?
How many types of memory areas are allocated by JVM in java?
How do you sort arrays in java?
Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..
Why is boolean important?
What is a container in a gui?
what is the difference between the methods sleep() and wait()? : Java thread
What is anagram of a string?
What data type is a string?
Is void a data type in java?
What flag up means?
What is character in data type?