A good answer might be:

  1. How many class definitions are there in this program?
    • Two: HelloObject, and HelloTester
  2. How many objects are created when the program runs?
    • Just one, in the statement:
      HelloObject anObject = new HelloObject();
    • The other class definition, HelloTester, is used to contain the static main() method. No object needs to be constructed from it.

Testing Class

Remember that the Java interpreter starts your program by looking for the main() method. Since this is a static method, it is in your code before anything starts running. It is convenient to have a separate testing class that serves no other purpose than to contain the main() method. No testing class objects will be constructed when the program runs. (However, main() will usually construct objects of other classes as it runs.)

You should name the file HelloTester.java. When you compile the file, the compiler will output two separate files of bytecodes:

C:\chap30>javac HelloTester.java
  compiling: HelloTester.java

C:\chap30>dir

11/13/98  10:07p                   257 HelloTester.java
11/13/98  10:40p                   476 HelloObject.class
11/13/98  10:40p                   373 HelloTester.class
               3 File(s)          1,106 bytes

When you run the program you should type:

java HelloTester
The Java interpreter will find the main() method in the HelloTester class and start it running.

QUESTION 10:

When the Java interpreter needs to use a definition of the HelloObject class, where will it be found?

Click Here after you have answered the question