2.3 Calling a Void Method
Enduring Understanding
Some objects or concepts are so frequently represented that programmers can draw upon existing code that has already been tested, enabling them to write solutions more quickly and with a greater degree of confidence.
Learning Objective
Call non-static void methods without parameters.
Essential Knowledge
An object’s behavior refers to what the object can do (or what can be done to it) and is defined by methods.
Procedural abstraction allows a programmer to use a method by knowing what the method does even if they do not know how the method was written.
A method signature for a method without parameters consists of the method name and an empty parameter list.
A method or constructor call interrupts the sequential execution of statements, causing the program to first execute the statements in the method or constructor before continuing. Once the last statement in the method or constructor has executed or a return statement is executed, flow of control is returned to the point immediately following where the method or constructor was called.
Non-static methods are called through objects of the class.
The dot operator is used along with the object name to call non-static methods.
Void methods do not have return values and are therefore not called as part of an expression.
Using a null reference to call a method or access an instance variable causes a NullPointerException to be thrown.
Last updated
Was this helpful?