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 / vishal
in the later case a different overloaded contructor is
invoked while in the prior case a different.As in the later
case a different constructor initializes the string s1 with
different values hence the result
Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
Can we have try without catch block?
What is difference between throw and throws ?
Can a abstract class be declared final?
What is main in java?
What is default switch case? Give example.
Can a java program have 2 main methods?
How do you sort a set in java?
What is a buffer in java?
What a static class can contains?
Explain features of interfaces in java?
What is substring in java?
What are variable arguments or varargs?
How can u increase the heap size in the memory?
Explain with example the concept of constant variable in java.
What is the use of predicate in java 8?