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
How do generics work in java?
String class is defined under which package in java?
What is Gang of four design patterns
What 5 doubled?
Can we instantiate interface in java?
What are the two ways in which thread can be created?
How do you create immutable object in java?
What about features of local inner class?
Garbage collection in java?
When should I use singleton pattern?
Can we force garbage collector to run ?
Why do we need strings in java?
What is a flag variable?
What is a local class in java?
Explain the difference between an object-oriented programming language and object-based programming language?