Writing Classes in AP Computer Science A
The data type of a mutator method's parameter is...
the same as the return type of the method.
always "String."
the same as the type of the instance variable being modified.
Mutator methods never have any parameters.
If a public mutator method inadvertently modifies a static field instead of an instance field in a class representing bank accounts, what consequence might that have on individual bank account objects?
Static methods within the class can no longer access or alter instance fields effectively locking down data modification capabilities completely.
Each bank account object's static fields become protected and inaccessible from other classes' methods directly.
Instance fields in each bank account object become final after first modification disallowing further updates entirely.
All bank account objects will unintentionally share and modify this single piece of data rather than maintaining unique values per account.
When refactoring a class DataAnalyzer
's mutator methods to improve performance, which modification will most likely reduce the time complexity when dealing with large datasets?
Including additional helper methods that use linear operations.
Looping through the dataset multiple times for data validation.
Changing a linear search to binary search within the mutator.
Adding more conditional checks inside the mutator.
If a class has no mutator methods, it is said to be...
transmutable
immutable
mutable
accessible
What advantage does encapsulating fields and providing public mutator methods have over typically using public fields?
Protects fields from being changed in undesired ways by external classes
Allows direct access to the variables in order to reduce the number of method calls needed
Reduces memory usage since no more methods are added
Increases execution time as fewer method checks are required
What type of value does a typical mutator method return in Java?
An updated value after setting it correctly.
The original value before modification occurred.
True or false based on successful modification.
No value; it has a void return type.
Which of the following best describes the purpose of a mutator method in an object-oriented program?
To create a new instance of a class with predefined states for its instance variables.
To modify the state of an object by changing the values of its instance variables.
To retrieve information about the state of an object without modifying it.
To compare two objects to determine if they have identical states and behaviors.

How are we doing?
Give us your feedback and let us know how we can improve
Why does the following class does not compile? public class Weather { private int currentTemp;
public Weather(int temp)
{
currentTemp = temp;
}
public void resetTemp(double newTemp)
{
currentTemp = newTemp;
}
}
The constructor has a parameter.
The newTemp variable does not exist.
The resetTemp has a return type of "void."
The resetTemp assigns a double value to an int variable.
Following the naming convention for mutators methods, what should the name of the method that updates the value of an instance variable named "age" be?
returnAge(int age)
setAge(int age)
getAge(int age)
printAge(int age)
Which type of Java method directly modifies instance variables within its own class?
Accessor method
Interface implementation
Method override
Mutator method