![]() |
![]() |
![]() |
![]() |
![]() |
|
With an isVegetable method defined for both the Vegetable and
Food classes, the method defined for the Vegetable class
will override the one defined for the Food class if, and only if,
isVegetable is sent to a Vegetable instance.
On the other hand, whenever isVegetable is sent to a Food
instance that is not a Vegetable instance, there is no overriding,
and the instance makes use of the isVegetable method defined for
Food, which answers false:
Workspace Transcript show: Food new isVegetable printString; cr; show: Vegetable new isVegetable printString; cr; show: Dairy new isVegetable printString; cr; show: Meat new isVegetable printString; cr; show: Grain new isVegetable printString; cr Transcript false true false false false