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
What is the replace tool?
Can a class be defined inside an interface?
What is runtime polymorphism or dynamic method dispatch?
What is formatted output in java?
Can we have return statement in finally clause? What will happen?
How do you identify if jvm is 32-bit or 64-bit from java program?
What is bifunction in java?
Is there a sort function in java?
Give me some null interfaces in java?
what do you understand by the term string with respect to java?
Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?
Why collection is called framework in java?
what is bmg file and how to create that files?what will it contailn?
What are advantages of using Java?s layout managers than windowing systems?
Explain java thread life cycle.