289: Highlights
- Inadvertent instance-variable accesses and assignments destroy data abstraction.
- You can prevent inadvertent direct access to instance variables by
making such instance variables private. Thus, the publicprivate
dichotomy helps to ensure that you can benefit from data abstraction.
- The public instance variables and public instance methods constitute the
class's public interface.
- If you want to provide universal access to instance variables and
methods, then mark them with the
public
keyword.
- If you want to limit access to instance variables and methods to the
class in which they are introduced and to subclasses of the class in
which they are introduced, then mark them with the
protected
keyword.
- If you want to limit access to instance variables and methods to the
class in which they are introduced, then mark them with the
private
keyword.