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


Please Help Members By Posting Answers For Below Questions

How do you break a loop?

566


What is the epoch date?

568


Can we use return in constructor?

495


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

2134


What is a arraylist in java?

560






What is 16 bits called?

501


How can you write a loop indefinitely in java programming?

552


How do you remove an element from an arraylist in java?

460


How thread scheduler schedule the task?

584


Can we have any code between try and catch blocks?

559


What does the three dot emoji mean?

584


What are methods in java?

540


how to run ecllipse with jettyserver for windows environment using batch file

1495


What is the purpose of format function?

625


Is a method a procedure?

559