In the file of bytecodes, HelloObject.class
.
Here is how the program runs.
(Remember that it is actually the bytecodes that are executed.
However it is
convenient to pretend that
the statements of the source program
run one after another
starting in main()
. )
class HelloObject // 2a. The class definition is { // used to make the object void speak() // 2b. Aspeak()
method { // is included in the object. System.out.println("Hello from an object!"); // 3a. Thespeak()
method // of the object prints a // message on the screen. // 3b. The method returns to the // caller. } } class HelloTester { public static void main ( String[] args ) // 1. Main starts running. { HelloObject anObject = new HelloObject(); // 2. AHelloObject
// is created. anObject.speak(); // 3. The object'sspeak()
// method is called. } // 4. The entire program is finished. }