English subtitles

← Accessors and Mutators - Intro to Java Programming

Get Embed Code
7 Languages

Showing Revision 4 created 05/24/2016 by Udacity Robot.

  1. In the last exercise that you did with Sarah, something remarkable happened.
  2. Here we have a string we call toUpperCase. And then, we look at what's in the
  3. variable on which we just invoked the method. And we notice that it does not
  4. contain the upper case version. So, calling this method did not modify or as we
  5. say, mutate the object. We say that toUpperCase is an accessor method, it
  6. leaves the object on which it is called unchanged. Instead, it returns a value
  7. and that value is then stored in this variable. The uppercased string is here,
  8. the original string is still here. Contrast that with that method call. Here we
  9. have a picture and we call the translate method on it. When the method is
  10. called, the picture changes. It is moved to a different location. We say the
  11. object has been mutated. It is now different than what it was before. And we
  12. call the translate method a mutator. So again, an accessor leaves the object on
  13. which it operates unchanged, and mutator changes or mutates the object.