Picture of 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:

No.

Picture of the Program

reference to an object

The speak() method is part of an object. It exists only when there is an object to contain it (unlike a static method that does not need an object). The picture shows the action, just as step 3 starts.

The variable anObject is a reference to the object that was constructed. That object contains the method speak(). So main() can find and activate speak() with:

anObject.speak();

You might think that this is a needlessly complicated way to write a message on the monitor. And you would be correct. But remember that this is a simple example of object oriented programming. Later on, when the task gets really complicated, using objects greatly simplifies programming. Writing large programs in Java takes only one third to one fifth of the time it takes to write in some other languages.

QUESTION 11:

Does the class HelloObject have a constructor?