153k views
3 votes
Another method that might be desired is one that updates the Goalie's jerseyNumber. This method will receive a new number of Jersey and set this number to the Goalie's current jerseyNumber. What methods would accomplish this?

User Nanoman
by
4.7k points

1 Answer

3 votes

Answer:

A setter method

Step-by-step explanation:

A setter method will accomplish this. A setter method is a method that takes in a value as an argument and grabs an object's instance variable and modifies it with the value passed as an argument. In this scenario, the argument value would be the current JerseyNumber. The setter method will grab the object's jerseyNumber variable and change its value to be the value of the passed argument. Setter methods are common practice in all object classes as well as the getter methods to retrieve instance variables.

User Gotschi
by
4.5k points