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 does snprintf return?
What is integer parseint?
What is a “stateless” protocol ?
What does serializing data mean?
What does the ‘static’ keyword mean? Is it possible to override private or static method in java?
What is constant in programming?
What is the purpose of a parameter?
What are the two ways in which thread can be created?
How will you calculate the depth of a binary tree if the tree contains 15 nodes?
Compare overloading and overriding?
can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread
What is the dot operator?
What is the difference between Java and C++?
What is void data type?
What is a conditional equation?