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
Give a practical example of singleton class usage?
Explain the difference between serializable and externalizable in java?
What is an empty class? What functionality does it offer in Java?
What is the protected method modifier?
In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?
What is the use of default method in interface in java?
Can Exception handling we can handle multiple catch blocks?
Does java vector allow null?
Explain wait() method of object class ?
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
Is arraylist ordered?
Can a class have multiple superclasses?
What are methods of a class?
Why string is not thread safe?
What are accessor methods in java?