How do you pass arguments to a void method, and how do parameters and arguments correspond?
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.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this topic is asking
The College Board (Topic 2.4) wants you to call a void method that takes parameters, passing arguments that match the parameter list in number, order and type, and to understand that for primitives the argument's value is copied into the parameter (pass by value). This is how a method receives the data it needs to do its job.
Parameters versus arguments
If a class defines void deposit(double amount), then amount is the parameter. When you call account.deposit(250.0), the value 250.0 is the argument, and it is copied into amount for that call. The names need not match; only the types and order must line up.
Matching number, order and type
So for void printLabel(String name, int copies):
printLabel("Tom", 3)matches (String, then int).printLabel(3, "Tom")does not - the order is wrong.printLabel("Tom")does not - too few arguments.
Pass by value
Java passes arguments by value: the value of the argument is copied into the parameter. For a primitive argument, the method works on its own copy, so changing the parameter inside the method does not change the caller's original variable. (Objects passed as arguments copy the reference, so the method can change the object's state through it, but that is a finer point; for primitives, the caller's variable is safe.)
Overloaded methods
A class can have several methods with the same name but different parameter lists - this is overloading. The compiler selects the version whose parameters match the arguments you pass. For example, print(int n) and print(String s) are two different methods; obj.print(5) calls the first, obj.print("hi") the second.
Try this
Q1. A method header is void setSpeed(int speed). Write a valid call on an object car that sets the speed to 60. [1 point]
- Cue.
car.setSpeed(60);
Q2. Explain why a void method changing its int parameter does not change the caller's matching variable. [2 points]
- Cue. Java passes primitives by value: the argument's value is copied into the parameter, so the method works on a copy and the caller's original variable is untouched.
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 2022 (style)1 marksMultiple choice. A class `Printer` has a void method `printLabel(String name, int copies)`. Which call is valid?
(A) `p.printLabel(3, "Tom");`
(B) `p.printLabel("Tom");`
(C) `p.printLabel("Tom", 3);`
(D) `p.printLabel("Tom", 3.0);`
(E) `printLabel("Tom", 3);`
Show worked answer →
The answer is (C).
Arguments must match the parameter list in number, order and type. printLabel(String name, int copies) expects a String then an int, so p.printLabel("Tom", 3) matches. (A) has the arguments in the wrong order (an int then a String). (B) passes only one argument. (D) passes a double where an int is required, which does not match. (E) omits the object reference, so the non-static method has no object to act on.
Markers reward matching number, order and type of arguments, and using dot notation on an object.
AP 2020 (style)4 marksFree response (code writing). A class `Account` has a void method `deposit(double amount)` and a void method `transfer(Account other, double amount)`. Write a code segment that creates two `Account` objects `a` and `b` (using a no-argument constructor), deposits 250.0 into `a`, then transfers 100.0 from `a` to `b`.
Show worked answer →
A 4-point question testing void calls with parameters, including an object parameter.
Account a = new Account();
Account b = new Account();
a.deposit(250.0);
a.transfer(b, 100.0);
Point 1: creating both objects. Point 2: a.deposit(250.0) passes a double argument matching the parameter. Point 3: a.transfer(b, 100.0) passes the other account and the amount in the correct order. Point 4: calling on the correct object (a, the source) with arguments matching the parameter list. Swapping the order in transfer, or passing the wrong types, loses marks.
Related dot points
- 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.
- 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 1.4 Compound Assignment Operators: use the compound assignment operators (+=, -=, *=, /=, %=) and the increment and decrement operators (++, --) as shorthand to update variables.
A focused answer to AP CSA Topic 1.4, covering the compound assignment operators, the increment and decrement operators, how each rewrites a longer assignment, and the integer-division traps they can hide, with a traced worked example.
Sources & how we know this
- AP Computer Science A Course and Exam Description — College Board (2025)