Java objects, reference variables and the garbage collection heap
<p>I know you can create 2 object reference variables, such as:</p>

<pre><code>Book b;
Book c;
</code></pre>

<p>And then create 2 objects and make the reference variables point to them:</p>

<pre><code>b = new Book();
c = new Book();
</code></pre>

<p>So now there are also 2 objects in the garbage collection heap.</p>

<p>If you assign <code>b</code> reference variable to <code>c</code>, i.e.:</p>

<pre><code>c = b;
</code></pre>

<p>1 of the objects in the GCH is now eligible for garbage collection, so you have 1 object there essentially.</p>

<p><br /></p>

<p>BUT What if you change something about <code>b</code>, for example:</p>

<pre><code>b.setAuthor("New Writer");
</code></pre>

<p>does that mean that if you used the reference variable <code>c</code> as such:</p>

<pre><code>c.getAuthor();
</code></pre>

<p>it would get <code>"New Writer"</code> because both b and c point to the same object? </p>

<p>It just seems odd because intuitively I would think that if you did <code>x = y</code>, then <code>y</code> should still remain distinct from <code>x</code> when you change things about either after the assignment.</p>
