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 / vishal

in the later case a different overloaded contructor is
invoked while in the prior case a different.As in the later
case a different constructor initializes the string s1 with
different values hence the result

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is defined as false sharing in the context of multithreading?

504


How many bytes is a url?

564


What is string pooling concept?

551


Why string is a class?

546


State the main difference between c++ and java?

592






What is the difference between method and means?

572


What are the library functions in java?

547


Explain the use of volatile field modifier?

631


What is the benefit of abstract class?

513


What is a superclass?

922


What is file in java?

558


How many types of exception can occur in a java program?

536


Can a class with private constructor be extended?

486


Explain the features of interfaces in java?

554


What is meant by 'Class access modifiers'?

551