next up previous
Next: About this document ... Up: In the Laboratory: Feeding Previous: Lab Exercise 3: Order

Lab Exercise 4: Generating a Trace

Add System.out.println() statements to your eat(String) method in order to generate a visible trace of the method call and return mechanism. Use println to display eat()'s parameter, and the food instance variable both before and after the assignment statement. Try to generate the following output:

    starting the eat method
    str parameter = bananas
    food instance variable = no food
    str parameter = bananas
    food instance variable = bananas
    exiting the eat method

Using println statements to display the values of variables and to trace program control is a good debugging technique. You will want to use this technique to locate bugs when things go wrong.



Ralph Morelli {Faculty}
12/22/1999