CS 6520 Homework 20

Exercise 20.1

Given the following class definition (in an untyped language):
  1. Show the evaluation of treeClass.new.grow.
  2. Define twigClass by overriding the initial height in treeClass to be 1. Your definition should refer to treeClass to take advantage of future improvements to treeClass's grow method.
  3. Define weedClass by overriding the grow in treeClass to grow the tree by 20.Your definition should refer to treeClass to take advantage of future changes to treeClass's initial height value.
  4. Define fruitTreeClass by adding a numfruits field to treeClass, initialized to 0, and override the grow method to add a new fruit each time the tree grows. (As usual, your definition should rely on treeClass's height and grow.)
  5. Define a fruitTreeMixin function that takes a tree class (could be treeClass, twigClass, or weedClass, for example) and returns a new fruit tree class derived from the given class.


Last update: Tuesday, April 4th, 2000
mflatt@cs.utah.edu