Chapter Summary

  • Classes have instance variables to store data and method definitions that perform actions.

  • Each class, instance variable, and method definition can be either public or private. Those that are public can be used or accessed anywhere. A private instance variable cannot be accessed by name outside of its class definition. However, it can be used within the definitions of methods in its class. A private method definition cannot be invoked outside of its class definition. However, it can be invoked within the definitions of methods in its class.

  • Instance variables should be private, even though as a result, they cannot be referenced by name except within the definition of a method of the same class.

  • Accessor methods return the value ...

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.