Introduction to OOP Chapter 11: Static and Dynamic Behavior: next previous audio real text

The Polymorphic Variable

The addition of object-oriented ideas in a statically typed languages adds a new twist. Recall the argument for substitution: an instance of a child class should be allowed to be assigned to a variable of the parent class:
var
	pet : Mammal;
	fido : Dog;
	felice: Cat;
begin
	pet := fido; // legal
	pet := felice; // legal
	fido := pet; // not legal!
Intro OOP, Chapter 11, Slide 05