English subtitles

← Do We Have Enough Information - Intro to Java Programming

Get Embed Code
7 Languages

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

  1. The answer is no, we don't have enough information, we should make an instance
  2. variable. The xCoord and yCoord variables are parameters in the constructor.
  3. Which means when the constructor is done running, they go away. So then when
  4. addFriend is called later, xCoord and yCoord don't exist anymore. We can't get
  5. the coordinates from the friend variable. We're talking about the coordinates
  6. for where to draw the circle. And the friend probably doesn't know anything
  7. about where the upper left corner of the current object is. We could take the
  8. coordinates in as parameters in the addFriend method, so it would be
  9. addFriend(Person friend) int x int y. But it would be a little weird if every
  10. time you called addFriend, you also had to pass in the x and y coordinates that
  11. you originally passed in in the constructor. So if we decide to make instance
  12. variables for x and y, where would we initialize them? That's one for you to
  13. think about yourself.