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

It will Give Compile time Error...

We can not declare again s1.

So the Compiler will give

s1 is already defined in main(java.lang.String[])

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain restrictions on using enum?

827


Which is better 64 bit or 32 bit?

695


How is it possible in java programming for two string objects with identical values not to be equal under the == operator?

772


What is a hashmap used for?

894


What is identifier with example?

799


What is numel matlab?

998


What is thread pool? How can we create thread pool in java?

839


what is the purpose of "virtual"?

800


What is the use of conditional statement?

745


What do you mean by platform independence? What is an interface?

790


How do you sort in java?

776


What is internal variable?

734


What do you mean by thread safe?

750


Is it necessary that each try block must be followed by a catch block?

785


What is the use of parse function in java?

719