No. However, the empty pair of parentheses ()
are required,
even if there is no parameter list.
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.
Examine the program.
HelloTester
object created when the program runs?