CS51 - Fall 2009 - Lecture 17

  • Lab 6 - TextPlay:
  • Description: <html> <pdf>
  • Discussion of topics on the midterm

  • in the real world we often describe objects as being similar to something else and then discuss the differences (eg. a strobe light is a light that flashes, a textbook is a book with examples and problems). inheritance lets us do the same in java.

  • basics of inheritance
  • when a class extends another class it becomes a subclass of that other class. alternatively, the other class is a superclass of the new class. The subclass inherits everything defined in the superclass.
  • think about using inheritance when several classes have similar behaviors.
  • for an example, see FallingObjects
  • notice how the constructor for the Hail and FallingLeaf classes works.