YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Finding Bugs with Tracing Part 2 - Intro to Java Programming

Get Embed Code
6 Languages

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

  1. I'm going to trace name, friends and numFriends. I start at the first line,
  2. create a new person with the name Sara. So name will be set to the name I
  3. passed in. Friends is empty, numFriends is 0. And then we're done with the
  4. constructor. We do the same thing for Chenghan. And now we add a friend to
  5. Sara. So in addFriend, friends will get longer, it'll be friends plus Chenghan
  6. and numFriends will go up by one. And then that method's done, so we go up to
  7. the next line. In sara.unfriend, we shorten friends, we replace Chenghan in a
  8. space with nothing. So friends goes back to being nothing and then we're done.
  9. Something went wrong here, though. I clearly have no friends in the list here.
  10. But here, my number of friends is still 1. We saw when that happened. In
  11. unfriend, we updated the list of friends, but didn't update the number of
  12. friends.