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 the method (or constructor) when the method (or constructor) is called. This is discussed further in another chapter.
This is a good program to copy to
Notepad to 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.)
When you run this program it writes:
Hello from an object!
The details of how this happens are discussed in the next page.