Immutable String Transformation
A method accepts a String parameter and attempts to modify it. Identify the output after the method completes its operation.
What is printed when the following Java program is compiled and run?
class TextHelper {
public String modify(String s) {
s = s + "X";
return s;
}
}
public class QuestionTrace {
public static void main(String[] args) {
String s = "A";
TextHelper t = new TextHelper();
String r = t.modify(s);
System.out.print(s + r);
}
}
A
AXAX
B
AXA
C
AAX
D
AA
Question Leaderboard
Not enough data yet to show leaderboard.
