3.4 Using Object References

As we have mentioned, an object reference points to the data of an object. The object reference and the object data are distinct entities. An object can have more than one object reference pointing to it, or an object can have no object references pointing to it.

In Example 3.3, we declare two SimpleDate object references, d1 and d2, and we instantiate their objects at lines 9 and 14. Lines 10–12 and 15–18 output the respective data member values of d1 and d2. Then, line 20 uses the assignment operator to copy the object reference d1 to the object reference d2. Note that only the value of the object reference is copied, not the object data. After line 20, both object references have the same value and therefore ...

Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.