TopSome Mysteries of objectdraw, ExplainedDescribing similar things

Describing similar things

Before we answer these questions, we need to consider some new concepts and their use within Java. Let's start by thinking about how we describe things in English. We often describe real world objects as being like something else but then describe what the difference is:

We'd like to be able to do similar things in Java, and these are exactly the kinds of things we can do with the keyword extends. The class we "extend" is the class that we are like. The constants, variables, and methods that we define indicate how the new class differs from the one that we are extending.

We have done this all semester to create WindowControllers and ActiveObjects. For example, consider the header

public class Fall extends WindowController

from our falling leaves example. Fall is a WindowController. It has the same behaviors and properties as other WindowControllers, except for the things that we specify: 1) how it it draws the display (defined in the begin method) and 2) how it responds to mouse clicks (creating a tree from which leaves fall).

Here, we call Fall the subclass and WindowController the superclass.


TopSome Mysteries of objectdraw, ExplainedDescribing similar things