next up previous
Next: Week 12 Up: Week 11 Previous: Midterm 2

Overloading, Inheritance, Polymorphism

We've spent some time talking about inheritance, and we said that this feature was made part of the language in order to save us time and help us write correct software. However, we need to talk about other features of inheritance that make it such a useful construction.

Imagine that we want to create a new class which is an extension of another class. In the superclass there is some method, call it A, that performs some function. In our new class, we want a method which does the same type of thing as A and we'd therefore like to have a method of the same name in our subclass, but unfortunately it doesn't do exactly the same thing, so we can't just use the A from the superclass. What we do in that case is just to write a new method of the same name in the subclass. When this method has the same return type and the same number and types of parameters as the method in the superclass, we say that the method in the subclass overrides the method in the superclass.

What this means is that the subclass method A is executed rather than the superclass method A -- it's an alternative implementation of the method.


next up previous
Next: Week 12 Up: Week 11 Previous: Midterm 2
Chris Trendall
Copyright ©Chris Trendall, 2001. All rights reserved.

2001-12-09