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

Give a practical example of singleton class usage?

593


Explain the difference between serializable and externalizable in java?

539


What is an empty class? What functionality does it offer in Java?

674


What is the protected method modifier?

563


In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?

839






What is the use of default method in interface in java?

551


Can Exception handling we can handle multiple catch blocks?

644


Does java vector allow null?

544


Explain wait() method of object class ?

632


Howto get an object that will perform date & time calculations then format it for output in some different locales with different date style.can ne1 tel me the answer of this question.pls

1446


Is arraylist ordered?

563


Can a class have multiple superclasses?

568


What are methods of a class?

544


Why string is not thread safe?

543


What are accessor methods in java?

555