6.5 Information Hiding Revisited

I don’t like to meddle in my private affairs.

—KARL KRAUS (1874–1936)

The material in this section is not needed to understand most of the rest of this book. If you prefer, you can safely postpone reading this material until you are more comfortable with classes. This section discusses a subtle problem that can arise when defining certain kinds of classes. The problem does not apply to any class you define whose instance variables are either of a primitive type—such as int, double, char, and boolean—or of the type String. So you can define lots of classes without being concerned with this problem.

Privacy Leaks

A class can have instance variables of any type, including any class type. These often can be natural ...

Get Java: An Introduction to Problem Solving and Programming, 8th 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.