Running the Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

In the file of bytecodes, HelloObject.class.

Running the Program

Here is how the program runs. It is actually the bytecodes that are executed. However it is convenient to discuss how the program works in terms of its statements, starting at main().


class HelloObject                                 // 2a.  The class definition is
{                                                 //      used to make the object

  void speak()                                    // 2b.  A speak() method
  {                                               //      is included in the object.


    System.out.println("Hello from an object!");  // 3a.  The speak() 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.  A HelloObject 
                                                  //     is created using its
                                                  //     default constructor.

    anObject.speak();                             // 3.  The object's speak() 
                                                  //     method is called.

  }                                               // 4.  The entire program is finished.
}

QUESTION 10:

Could you activate the speak() method without creating an object?