I have a question concerning one of Mock Exam Problems:
What is the result of compiling and executing the following program:
public class Test2{
public static void main(
String[] args) {
String message="hello";
new Test2().run(message);
System.out.println(message);
}
public void run(String text) {
text += " world,"
System.out.println(text);
}
A) hello world, hello world
B) hello world, hello
-------------------------------------------------
I thought the solution should be B as the method receives a copy of the original reference. Therefore the text now points to a new object which concats the "world," string. While message reference should point to the original unmodified "hello" string object. However the answer listed is A. Could someone please inform me of where the error in my logic is!