Hello all! I'm new in the forum and I'm studying for the
SCJP and plan to take the exam in December. Hopefully we can help each other with any problems that we have.
So far I have this problem: I have 2 ref vars that each refer to 2 different objects, and then I set both variables to refer to the same object. My understanding is that if I make a change in one object's value, the change should be done in the other variable as well, but that is not working in my code.
The code that I have is below. Any suggestions or help is greatly appreciated. Thanks.
------ code below --------
class
Test {
public static void main (
String [] args) {
String first = new String("first");
String last = new String ("last");
// display original vals
System.out.println("first: " + first + "\tlast: " + last);
// chg references
last = first;
// this assignment should modify the reference pointed to by "first"
last ="new value";
// test: display first to see if its value has been changed.
System.out.println(first);
}
}