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

Which package has light weight components in java programming?

667


Can a class be protected in java?

491


what is the constructor and how many types of constructors are used in java?

528


What is meant by JVM? Is JVM platform independent or not?

569


What is the dot operator?

561






Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?

645


Explain when classnotfoundexception will be raised ?

560


What is the difference between path and classpath variables?

518


What is a jagged array in java?

528


Which api is provided by java for operations on set of objects?

898


What is method in research paper?

567


What is a wrapper method?

528


Tell me about different OOPS concepts.

584


Does sprintf add a null terminator?

550


Define how objects are stored in java?

557