3.4 Instance Variables, set Methods and get Methods
In Chapter 2, we declared all of an application’s variables in the application’s main
method. Variables declared in the body of a particular method are known as local variables and can be used only in that method. When that method terminates, the values of its local variables are lost. Recall from Section 1.6 that an object has attributes that are carried with it as it’s used in a program. Such attributes exist before a method is called on an object, while the method is executing and after the method completes execution.
A class normally consists of one or more methods that manipulate the attributes that belong to a particular object of the class. Attributes are represented as variables in ...
Get Java How to Program (early objects), 9/e 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.