Return to Video

Drawable Equals New Rectangle - Intro to Java Programming

  • 0:00 - 0:03
    The answer is, you can't assign an object of a class to a variable of an
  • 0:03 - 0:07
    interface type the object's class does not implement. We've seen that it's
  • 0:07 - 0:11
    possible to assign an object of a class to a variable of an interface type. And
  • 0:11 - 0:13
    this declaration isn't trying to assign a value of an interface type to a
  • 0:13 - 0:18
    variable of a class type. We can create a rectangle without too much trouble,
  • 0:18 - 0:23
    but rectangle doesn't implement drawable. So we can't store the rectangle that
  • 0:23 - 0:27
    we created in a variable of type drawable. This is a little bit weird, since
  • 0:27 - 0:30
    the rectangle actually does have a draw method, and the drawable interface
  • 0:30 - 0:35
    promises that it will have a draw method and nothing else. The problem is that
  • 0:35 - 0:39
    rectangle doesn't say that it implements drawable. For all Java knows, these
  • 0:39 - 0:44
    two drawable methods could be completely different. If we wanted to save a
  • 0:44 - 0:48
    rectangle in a drawable variable, we would need to change the rectangle class
  • 0:48 - 0:51
    to say that it implements drawable.
タイトル:
Drawable Equals New Rectangle - Intro to Java Programming
概説:

more » « less
Video Language:
English
Team:
Udacity
プロジェクト:
cs046: Intro to Programming
Duration:
0:52

English subtitles

改訂 Compare revisions