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 / jay
First the JVM will creates two objects s and s1 separately
when s=s1 is done JVM creates the new object and stores the
string "raj" in that object.But it does not modify the
contents of string s.After creating the new object the
reference of s is adjusted to refer the new object.
The point we observe here is that the contents of of the
string s is are not modified.This is the reason Strings are
called Immutable.The old object that contains "kapil" has
lost its reference.so it is called "Unreferenced object" the
garbage collector will removes it from memorey.
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
How do you break a loop?
What is the epoch date?
Can we use return in constructor?
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
What is a arraylist in java?
What is 16 bits called?
How can you write a loop indefinitely in java programming?
How do you remove an element from an arraylist in java?
How thread scheduler schedule the task?
Can we have any code between try and catch blocks?
What does the three dot emoji mean?
What are methods in java?
how to run ecllipse with jettyserver for windows environment using batch file
What is the purpose of format function?
Is a method a procedure?