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

How to invoke external process in java.

792


Explain working of call by reference function invoking.

803


What is a ternary operator in java? What is an interface?

781


Which is a valid identifier?

788


What does file separator do in java?

763


What is meant by main method?

800


Difference between static binding and dynamic binding?

803


What is the meaning of nullable?

792


This abstract class is correct ? abstract class A { public abstract void Disp(); public abstract void B() { } public absract virtual C() { } }

769


How to sort a collection of custom Objects in Java?

837


What data type is string java?

774


What are runtime exceptions?

915


Is java free for businesses?

823


What are the access modifiers in java?

812


What is the full form of jpeg?

747