To answer this question, let's go through each line of code:
String s1 = new String("amit");
- This line creates a new String
object s1
with the value "amit".
String s2 = s1.replace('m','i');
- This line creates a new String
object s2
by replacing the character 'm' with 'i' in s1
. So, the value of s2
will be "aiit".
s1.concat("Poddar");
- This line concatenates the string "Poddar" to s1
, but the result is not assigned to any variable. Therefore, the value of s1
remains unchanged, which is still "amit".
System.out.println(s1);
- This line prints the value of s1
, which is "amit".
System.out.println((s1+s2).charAt(5));
- This line concatenates s1
and s2
using the +
operator, resulting in "amitaiit". It then retrieves the character at index 5, which is 'a', and prints it.
The correct answer is D) "amit I".