7.7 Writing Data Manipulation Methods
Now we finally get down to the business of the class. Usually you will define a class not only to encapsulate the data, but also to provide some service. Thus, you would provide one or more methods that perform the functionality of the class. These methods might calculate a value based on the instance variables and/or parameters, or manipulate the instance variables in some way. The API of these methods depends on the function being performed. If a method merely manipulates the instance variables, it requires no parameters because instance variables are accessible from any method and, therefore, are in scope.
For example, in our Auto class, part of the functionality of our class is to calculate miles per ...
Get Java Illuminated, 5th 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.