No.
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 as step 3 starts.
The variable anObject
refers to the object that was constructed.
That object contains the speak()
method.
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.
The Hello.java
program of chapter 5 is
really all you need.
But later on, when tasks gets 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.
Does the class HelloObject
have a constructor?