go to previous page   go to home page   go to next page highlighting

Answer:

Oh... about four.


A Forest for the Trees

Forest Object and four Tree Objects

Some forests have more than four trees. But for us, let's stick to four. A more realistic Forest object would have many trees, and this would call for an array or other data structure. Those are topics of future chapters.

// Forest.java
//
public class Forest
{
  // instance variables
  private Tree tree0=null, tree1=null, tree2=null, tree3=null;
  
  ...
}

Our Forest object is composed of four reference variables that each point to a Tree. Although you think of a Forest as being composed of four objects, what it really has is references to those objects (which in turn reference yet other objects.)

When a Forest is complete there will be 13 objects: a Forest object, composed of four Tree objects, each composed of a Cone object and a Cylinder object.


QUESTION 13:

(Review: ) The reference variables of Forest are initialized to null. What does null mean?


go to previous page   go to home page   go to next page