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


Please Help Members By Posting Answers For Below Questions

What is the replace tool?

551


Can a class be defined inside an interface?

565


What is runtime polymorphism or dynamic method dispatch?

524


What is formatted output in java?

501


Can we have return statement in finally clause? What will happen?

517






How do you identify if jvm is 32-bit or 64-bit from java program?

538


What is bifunction in java?

680


Is there a sort function in java?

575


Give me some null interfaces in java?

605


what do you understand by the term string with respect to java?

531


Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?

572


Why collection is called framework in java?

540


what is bmg file and how to create that files?what will it contailn?

1891


What are advantages of using Java?s layout managers than windowing systems?

1861


Explain java thread life cycle.

583