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
Define how can we find the actual size of an object on the heap?
What is annotation in java?
Which is better stringbuffer or stringbuilder?
What are the disadvantages of object oriented programming?
Can a private method be declared as static?
What is the history of java?
What type of variable is gender?
Can we increase array size dynamically in java?
What is method overloading with type promotion?
What is the console in java?
How do you check if a character in a string is a digit or letter?
Can you tell me range of byte?
Is string a class?
What is the byte order of byte buffer?
What is remote method invocation (rmi)?