Privacy Leaks
A class can have instance variables of any type, including any class type. These often can be natural and useful things to have. However, using instance variables of a class type can introduce a problem that requires special care. The problem occurs because variables of a class type contain the memory address of the location where an object is stored in memory. For example, suppose that good Guy and bad Guy are both variables of the class type Pet, which we defined in Listing 6.1. Now suppose that good Guy names some object and your program executes the following assignment statement: