Illustration

Here is a slide that illustrates some of these possibilities. Variable x is a Textwindow. Variable a is a Window, b a pointer to a window, and c a pointer to a textwindow. Class Window defines a method called oops, and this method is redefined in the subclass TextWindow.

If we assign x to a, the value ceases to be a TextWindow, and becomes a Window. Executing the oops function yields the Window version.

If we assign the address of x to the pointer value b; the oops function executed might either be the one associated with Window or with TextWindow, depending upon whether or not it was declared as virtual in the class Window.

If we assign the address of x to the pointer value c, the oops function will always execute the TextWindow version, regardless whether or not it was declared as virtual in the class Window.

[audio] [real] Text to accompany slide10, in Chapter 12 of An Introduction to Object-Oriented Programming