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
Is string a class in java?
What happens if I remove static from main method?
Implementations of set interface?
What is wrapper class html?
Is java developer a good career?
What Is Query Throttling in java?
What are register variables what are the advantages?
How to run a JAR file through command prompt?
Is java ee a framework?
What is the difference between throw and throws keywords?
How objects of a class are created if no constructor is defined in the class?
What is immutability in java?
Explain the difference between call by refrence and call by value?
What’s the difference between constructors and other methods?
java program with complete 4 oops concepts implemented example