My textbook defined a mutator method as a method that modifies the object on which it operates.
And, it defines an accessor method as a a method that queries the object for some information without changing it.
Am I correct in saying nextInt is an accessor method?
My reasoning is that nextInt does not modify the object on which it operates. If I have created a Scanner object called in, when I write "int a = in.nextInt();" it does not modify the actual Scanner object. Instead, it is used as a kind of getter method to assign a value to a.
Actually, from the javadoc:
public int nextInt(int radix)
Scans the next token of the input as an int. This method will throw InputMismatchException if the next token cannot be translated into a valid int value as described below. If the translation is successful, the scanner advances past the input that matched.
...
This tells that the state of the scanner is altered after calling the method. So this makes nextInt
a mutator.
Therefore, nextInt
is both a mutator and an accesor.