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
Can we have any other return type than void for main method?
What are the differences between processes and threads?
What are the main uses of this keyword?
What modifiers may be used with an inner class that is a member of an outer class in java programming?
What is meant by class?
What are the restriction imposed on a static method or a static block of code?
What is the escape character in java?
What is the use of static methods?
What is the flag in java?
What are the main concepts of oops in java?
What is the difference between length and length() method in java?
why using interface interface ?
What is the difference between ArrayList and Vector? which one is better in Java
If we don’t want some of the fields not to serialize how to do that?
Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example