Introduction to OOP: Chapter 12: Implications of Inheritance [next] [previous] [audio] [real] [text]

Type Conversion - Reverse Polymorphism

We have seen already how it is possible for a variable to be assigned a value derived from a subclass. Can this be reversed - that is, can a value from a parent class be assigned to a value from a subclass?

var
	x : Window;
	y : TextWindow;

begin
	x := y;	 // legal
	y := x;	// is this legal??
end;
Intro OOP, Chapter 12, Slide 18