April 2019
Intermediate to advanced
360 pages
9h 17m
English
The first class in our example is the GameMission class. As you can see, we have two class variables. The percentageCompleted int is private and the getPercentageCompleted() accessor method is used to obtain the variable's value. The second class variable is previousPercentageCompleted. This is assumed private to the current Java package; there is no associated accessor method for this variable:
public class GameMission { // class variables private int percentageCompleted; int previousPercentageCompleted; // constructor public GameMission() { percentageCompleted = 0; previousPercentageCompleted = 0; } // mutator public void setPercentageCompeted(int percentage) { previousPercentageCompleted = percentageCompleted ...
Read now
Unlock full access