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

Can we have try without catch block?

637


What is difference between throw and throws ?

592


Can a abstract class be declared final?

560


What is main in java?

504


What is default switch case? Give example.

572






Can a java program have 2 main methods?

541


How do you sort a set in java?

512


What is a buffer in java?

567


What a static class can contains?

692


Explain features of interfaces in java?

548


What is substring in java?

613


What are variable arguments or varargs?

562


How can u increase the heap size in the memory?

548


Explain with example the concept of constant variable in java.

617


What is the use of predicate in java 8?

488