Inheritance defined |
When we extend a class, our new class (the subclass) "inherits" everything that is defined in the first class. We can use the things that we have inherited as if we had defined them in the subclass.
So when we extend WindowController, we can use the canvas instance variable defined in WindowController, we can call methods like getImage and getAudio defined in Controller, and the add method provided by Applet. When we used these methods, we called them as if they were locally defined, usually just with the method name, though we could have specified the optional this. prefix to clarify that the method is part of this class, or as we have now seen, part of a class we extended. Our class that extends WindowController need only define that which is different - the exact components on the display and how they react to input.
We have also seen extensions of ActiveObject. ActiveObject defines
Each extension of ActiveObject inherits these capabilities, and defines how it differs - initializing itself in its constructor, and defining its "active" behavior in the run method.
Inheritance defined |