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

Does list allow duplicates in java?

700


How many bits is size_t?

742


What is an empty class? What functionality does it offer in Java?

962


Tell me about different OOPS concepts.

782


Compare overloading and overriding?

781


Does java support function overloading, pointers, structures, unions or linked lists?

826


Can I use % with real numbers?

752


What is a ?

962


What is the difference between the prefix and postfix forms of the ++ operator?

781


What is the memory leak in java?

741


What is javac used for?

698


Difference between overriding and overloading in java?

824


What is the largest long allowed by java?

778


What is charat ()?

722


What is a Hash Table? What are the advantages of using a hash table?

853