Quiz: Accessor or Mutator?
Consider this code:
String greeting = "Hello";
System.out.println(greeting.replace("H", "J"));
System.out.println(greeting);
| What is the first line of the printout? (Don't type quotation marks—they don't appear in the output.) | Jello |
The H was replaced with a J. |
| What is the second line of the printout? | Hello |
The value of greeting has not changed. The replace method produces a new string with the result. |
What kind of method is replace, accessor or mutator? |
accessor | The replace method does not mutate the object on which it is called. |
Be sure to watch the answer video so you get to see the mean and nice cat!