Got a YouTube account?

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

English subtitles

← Another Way to Implement Get Friends - Intro to Java Programming

Get Embed Code
5 Languages

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

  1. But there's another way I might have implemented this getFriends method. I
  2. could just add a toString method to the Person class. If the toString method
  3. returns the name, then I could implement getFriends the way I did before. So
  4. here's approximately what I had before, and if I run the tester again, I can
  5. see that the getFriends method is working. This is because when I called
  6. toString on the arraylist of Friends, it uses each friend's toString method, to
  7. get it's name. Well, actually just to get a representation of it, which in this
  8. case, is the name. This implementation will work, so long as I don't want the
  9. person to return something more than the name, in its toString method.