Repair the treadmill setter

A treadmill stores its speed in the field shown below, but its intended mutator leaves that field unchanged. The supplied parameter has the same name as the field.


Java
private int speed = 3;

public void setSpeed(int speed) {
    speed = speed;
}


Keep the right-hand side as speed. Replace only the left-hand side with so that the assignment updates the object's field.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Accessors and Mutators Questions: