Bruce Eckel's Thinking in Java Contents | Prev | Next

Exercises

  1. Create a class with a default constructor (one that takes no arguments) that prints a message. Create an object of this class.
  2. Add an overloaded constructor to Exercise 1 that takes a String argument and prints it along with your message.
  3. Create an array of object handles of the class you created in Exercise 2, but don’t actually create objects to assign into the array. When you run the program, notice whether the initialization messages from the constructor calls are printed.
  4. Complete Exercise 3 by creating objects to attach to the array of handles.
  5. Experiment with Garbage.java by running the program using the arguments “before,” “after” and “none.” Repeat the process and see if you detect any patterns in the output. Change the code so that System.runFinalization( ) is called before System.gc( ) and observe the results.

d

Contents | Prev | Next