String is an immutable object.
Then how can the following code be justified.
String s1 = ?ABC?;
String s1 = s1+?XYZ?;
s.o.p(s1);
The output is ABCXYZ, which is the value of s1 ?
Answer Posted / k.shiva
here we define s1="ABC".That means one new string is
created.And this string value is stored in heap its
refrence variable is s1.when we say s1+"XYZ".Then string s1
i.e ABC and XYZ are concadinated by using concadination
operater.It forms a new string i.e "ABCXYZ" in heap.But
again we assign this value to the refrence variable
s1.Then "ABCXYZ" value is assign to s1 and the string "ABC"
which is garbage collected.
| Is This Answer Correct ? | 12 Yes | 4 No |
Post New Answer View All Answers
Explain JMS in detail.
What is methods and methodology?
What happens if an exception is throws from an object's destructor?
What is a default constraint?
Write a program in java to find the maximum and minimum value node from a circular linked list.
What about interrupt() method of thread class ?
What do you know about the garbate collector?
What is the difference between keyword and identifier?
What are different types of inner classes ?
What is difference between local variable and global variable?
What are annotations in java?
Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?
What are static initalizers in java ?
What is xslt in java?
What is meant by design patterns?