Hey guys,
Sorry for the indescriptive title, couldn't think of a better one.
I'm currently learning from a book, "Learn
Java 6 in 21 Days". I'm at the topic of object that reference to other objects instead of creating new ones.
Take the following code:
With the result being:
string1: Peanuts
string2: Free the bound periodicials.test
Same object? false
Same value? false
In the book they state that
Creates a reference rather then a new object. Therefore I would expect the output of str2 when it prints to be "Peanutstest". Here is why I am thinking this:
Since str2 references to str1 in the 3rd line above, I would expect str2 to change to "Peanuts" when I change str1.
Can anyone explain to me where I am going wrong in this way of thinking?
Thank you.