How do you call a void method on an object using dot notation, and what does void mean?
Topic 2.3 Calling a Void Method: call a non-static void method on an object using dot notation, and explain that a void method performs an action but returns no value.
A focused answer to AP CSA Topic 2.3, covering dot notation for calling methods on objects, what void means, why a void call cannot be used in an expression, the difference between a method signature and a call, and method side effects, with a worked example.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
What this topic is asking
The College Board (Topic 2.3) wants you to call a non-static void method on an object using dot notation (object.method();), and to understand that a void method performs an action but returns no value, so its call cannot be used as a value in an expression. This is the simplest form of method call and the template for the parameter and return-value variants that follow.
Dot notation
For example, if account refers to a BankAccount object with a method printStatement, you call it with:
account.printStatement();
The object to the left of the dot is the one the method acts on. A non-static method must be called on an object; calling it on the class name does not work, because there is no specific object for it to act on.
What void means
A void method typically has a side effect: it changes the object's state (an attribute), prints output, or otherwise affects the program, rather than computing and handing back a result. System.out.println(...) is itself a void method - it displays text but gives you nothing back. Trying to write int x = lamp.turnOff(); is a compile-time error, because turnOff returns nothing to store.
Signature versus call
The class defines a method's signature - its name and the types of its parameters, for example void deposit(double amount). When you call the method, you supply arguments that match the parameter list. For a no-argument void method the parentheses are empty, but they are still required: omitting them (lamp.turnOff) is not a method call and will not compile.
Try this
Q1. Write a statement that calls a void method start() on an object referred to by engine. [1 point]
- Cue.
engine.start();
Q2. Explain why double d = pump.fill(); does not compile if fill is a void method. [2 points]
- Cue. A void method returns no value, so there is nothing to assign to
d; using a void call where a value is expected is a compile-time error.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2021 (style)1 marksMultiple choice. A class `Robot` has a void method `turnLeft()`. Given `Robot r = new Robot();`, which statement correctly calls the method?
(A) `turnLeft(r);`
(B) `r.turnLeft();`
(C) `Robot.turnLeft();`
(D) `int x = r.turnLeft();`
(E) `r.turnLeft;`
Show worked answer →
The answer is (B).
A non-static method is called on an object using dot notation: the object reference, a dot, the method name, and parentheses for the (empty) argument list. (A) uses the wrong syntax and treats r as an argument. (C) tries to call it on the class, but the method is non-static. (D) tries to store a returned value, but a void method returns nothing, so this does not compile. (E) omits the parentheses, so it is not a method call.
Markers reward the dot-notation pattern object.method(); and knowing a void method returns no value to store.
AP 2019 (style)3 marksFree response (code writing). A class `Light` has void methods `turnOn()`, `turnOff()` and `dim()`. Write a code segment that creates a `Light` object named `lamp`, then turns it on, dims it, and turns it off, in that order, by calling the methods on the object.
Show worked answer →
A 3-point question testing void method calls with dot notation.
Light lamp = new Light();
lamp.turnOn();
lamp.dim();
lamp.turnOff();
Point 1: creating the Light object with new. Point 2: calling all three methods on lamp using dot notation with parentheses. Point 3: calling them in the required order (on, dim, off). Writing lamp.turnOn without parentheses, or trying to store a return value, would be wrong.
Related dot points
- Topic 2.4 Calling a Void Method with Parameters: call a void method that takes parameters, passing arguments that match the parameter list in number, order and type, and explain how arguments are copied to parameters.
A focused answer to AP CSA Topic 2.4, covering parameters versus arguments, matching the argument list in number, order and type, pass-by-value for primitives, overloaded methods, and how the call supplies data to the method, with a worked trace.
- Topic 2.5 Calling a Non-void Method: call a method that returns a value, and use the returned value by storing it, printing it, or including it in an expression.
A focused answer to AP CSA Topic 2.5, covering methods that return a value, the return type, using a returned value in an assignment, expression or print, the difference from a void method, and chaining method calls, with a worked trace.
- Topic 2.2 Creating and Storing Objects (Instantiation): use the new keyword to call a constructor and instantiate an object, choosing the correct constructor by its parameters, and store the result in a reference variable.
A focused answer to AP CSA Topic 2.2, covering the new keyword, constructors and how they initialise an object, choosing a constructor by its parameter list, matching argument types, storing the reference, and the meaning of null, with a worked example.
- Topic 2.1 Objects: Instances of Classes: explain the relationship between a class and its objects, and describe an object as an instance of a class with state and behavior.
A focused answer to AP CSA Topic 2.1, covering the class-object relationship, what it means for an object to be an instance, the difference between attributes (state) and methods (behavior), and reference versus primitive variables, with a worked example.
- Topic 2.7 String Methods: call the String methods in the AP Java subset (length, substring, indexOf, equals, compareTo), respecting zero-based indexing and the immutability of String objects.
A focused answer to AP CSA Topic 2.7, covering the required String methods length, substring (both forms), indexOf, equals and compareTo, zero-based indexing, the half-open range of substring, why == differs from equals, and String immutability, with a worked trace.
Sources & how we know this
- AP Computer Science A Course and Exam Description — College Board (2025)