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 / paras bist

above program is incorrect ,it will give compile time error
as "Duplicate Variable s1".
it should b
String s1 = "ABC";
String s = s1+"XYZ";
which is valid in string ,as we are creating new String
object

Is This Answer Correct ?    14 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is hash in java?

523


Explain enumeration in java?

567


What is difference between fail-fast and fail-safe?

586


What is static keyword?

591


Is map sorted in java?

566






Define inheritance?

554


Explain about member inner classes?

588


What is a default constraint?

616


What is a java developer salary?

544


Explain about exception propagation?

585


What are the advantages of java over cpp?

553


Explain about transient variables in java?

640


How to compare two strings in java program?

671


Can we override the static methods?

572


Does the order of public and static declaration matter in main method?

616