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
Explain thread life cycle in java?
Can we restart a dead thread in java?
Explain the concept of hashtables?
What is get () in java?
What do you understand by an io stream?
How is treeset implemented in java?
Can we cast any other type to boolean type with type casting?
How do you use wildcards?
How would you format a date in java? I.e. In the ddmmyyy format?
What is default locale java?
What is void keyword?
What are the skills required for core java?
What is the integer of 16?
How many ways can you break a singleton class in java?
What is the protected method modifier?