No.
You need only one main()
method for the
Java virtual machine to use in starting your program.
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(); } }
Above is a complete program which includes a class definition.
The definition of class HelloObject
includes a method but no instance variables.
When the main()
method starts it constructs
a HelloObject
and then invokes its speak()
method.
Objects of this class have no instance variables. The class does have a constructor but it is not explicitly defined in the code (this will be discussed further).