Answer:

No. However, the empty pair of parentheses () are required, even if there is no parameter list.

Parameter Lists

class HelloObject
{
  // method definition
  void speak()
  {
    System.out.println("Hello from an object!");
  }
}

class HelloTester
{
  public static void main ( String[] args )
  {
    HelloObject anObject = new HelloObject();
    
    anObject.speak();
  }
}

A parameter list is a list of values that is given to a method (or constructor) when a method (or constructor) is called. This is discussed further later in this chapter.

This is a good program to copy to a text editor and run. Save the file as HelloTester.java. Remember that the file name must match the name of the class that contains the main() method. (Also remember that upper and lower case are important both in the file name and in the class name.) Here is an example run:

C:\>javac HelloTester.java
C:\>java HelloTester
Hello from an object!
C:\>

The details of how this happens are discussed in the next page.


QUESTION 9:

Examine the program.

  1. How many class definitions are there in this program?
  2. Is a HelloTester object created when the program runs?