Fiveable

💻AP Computer Science A Unit 1 Review

QR code for AP Computer Science A practice questions

1.9 Calling a Void Method With Parameters

1.9 Calling a Void Method With Parameters

Written by the Fiveable Content Team • Last updated June 2026
Verified for the 2027 exam
Verified for the 2027 examWritten by the Fiveable Content Team • Last updated June 2026
💻AP Computer Science A
Unit & Topic Study Guides

Frequently Asked Questions

Previous Exam Prep

Study Tools

Exam Skills

AP Cram Sessions 2021

Pep mascot

A method signature is the method name plus the ordered list of its parameter types, and Java uses it to tell methods apart when several share a name. The return type is not part of the signature, so two methods cannot differ only by what they return. For AP Computer Science A, use signatures to decide which method call is valid and how each argument matches a parameter.

Why This Matters for the AP Computer Science A Exam

Reading and using method signatures shows up across the AP Computer Science A exam. On the multiple-choice section, you will trace code and decide which method call is valid based on the method name and parameter types, including cases with overloaded methods. On free-response code writing, you have to write methods that match a given specification exactly, so understanding signatures keeps your parameter order, types, and call structure correct.

This topic also builds the habit of procedural abstraction: using a method by knowing what it does, not how it works inside. That skill carries into reading the provided Java Quick Reference and working with user-defined classes that appear in both multiple-choice and free-response questions.

Key Takeaways

  • A method signature is the method name plus the ordered list of parameter types; the return type is not included.
  • Order and type of parameters matter, so divide(int, double) and divide(double, int) are different signatures.
  • Methods with no parameters still use empty parentheses, like getName(), and those parentheses are part of the call.
  • Parameters are the variables in the method header; arguments are the actual values you pass when calling.
  • Arguments must match the parameter list in number, order, and compatible type, because Java passes them using call by value (the method gets copies).
  • Void methods do not return a value and are called as statements; non-void methods return a value you store or use in an expression.

Key Concepts

Method Signatures: A Method's Unique ID

A method signature consists of the method name and the ordered list of parameter types. The signature for calculateArea(double, double) tells you the method is named calculateArea and takes two double parameters. Order matters, so divide(int, double) is different from divide(double, int).

Return type is not part of the signature. This is important. You cannot have both int getValue() and double getValue() in the same class because they have identical signatures, and Java would not know which one to call. This is also how overloading works: methods are overloaded when they share a name but have different signatures.

For methods without parameters, the signature is just the name with empty parentheses, like getName(). Those parentheses are required because they are part of the call even when empty. Without them, you are referring to a variable, not a method.

Parameters and Arguments

Parameters are variables declared in a method's header that receive values when the method is called. When you define public void greet(String name), the parameter name is a placeholder for whatever String value gets passed in. You can use that parameter inside the body of the method.

The values you pass when calling a method are called arguments. If parameters are placeholders, arguments are the actual values. When you call greet("Alice"), "Alice" is the argument assigned to the parameter name.

Java passes arguments using call by value, which means the parameters are initialized with copies of the arguments. The arguments you pass must be compatible in number and order with the types in the parameter list. This is why parameters make methods flexible and reusable: the same method can process different data each time it is called.

Void vs Non-Void Methods

Void methods perform actions but do not return a value. You call them as standalone statements, like System.out.println("Hello"). Because there is no value to work with, you cannot use a void method as part of an expression or store its result.

Non-void methods return a value whose type matches the return type in the header. To use that value, you store it in a variable or use it in an expression, such as int len = str.length(); or if (isValid(input)).

The distinction affects how you call methods. Calling a non-void method without using its return value is legal but usually pointless, since the result is thrown away. Trying to store the "result" of a void method is an error.

How a Method Call Affects Program Flow

A method call interrupts the sequential execution of statements. The program jumps into the method, runs its statements, and then returns to the point right after where the method was called. Control returns once the last statement runs or a return statement executes.

This connects to procedural abstraction: you can use a method by knowing what it does, not how it works inside. When you call Math.sqrt(25), you know it returns 5.0 without understanding the algorithm. The same idea lets you use str.length() or System.out.println() without knowing their internal details, so you can build on code others have written.

Code Examples

Method signatures in action:

</>Java
// Example: Understanding method signatures
public class SignatureDemo {
    // Method 1: Signature is add(int, int)
    public int add(int a, int b) {
        return a + b;
    }

    // Method 2: Signature is add(double, double) - different from Method 1
    public double add(double a, double b) {
        return a + b;
    }

    // Method 3: Signature is add(int, int, int) - different from Methods 1 & 2
    public int add(int a, int b, int c) {
        return a + b + c;
    }

    // This would be an ERROR - same signature as Method 1
    // public double add(int x, int y) {  // Can't differ only by return type!
    //     return x + y;
    // }

    // Method with no parameters: Signature is getRandomNumber()
    public int getRandomNumber() {
        return (int)(Math.random() * 100);
    }

    // Void method: Signature is printMessage(String)
    public void printMessage(String message) {
        System.out.println("Message: " + message);
    }
}

Using methods based on their signatures:

</>Java
// Example: Calling methods with different signatures
public class MethodCalls {
    public static void main(String[] args) {
        SignatureDemo demo = new SignatureDemo();

        // Java picks the right method based on argument types
        int sum1 = demo.add(5, 3);           // Calls add(int, int)
        double sum2 = demo.add(5.5, 3.2);    // Calls add(double, double)
        int sum3 = demo.add(1, 2, 3);        // Calls add(int, int, int)

        // No parameters - still need parentheses
        int random = demo.getRandomNumber();  // Calls getRandomNumber()

        // Void method - called as a statement
        demo.printMessage("Hello!");          // Calls printMessage(String)

        // This would be wrong - void method has no return value
        // String result = demo.printMessage("Hi");  // ERROR!
    }
}

Parameters vs arguments in practice:

</>Java
// Example: Parameters are variables, arguments are values
public class ParameterExample {
    // Parameters: base and height
    public static double triangleArea(double base, double height) {
        // Parameters act like local variables inside the method
        return 0.5 * base * height;
    }

    // Parameter: fahrenheit
    public static double toCelsius(double fahrenheit) {
        // Can use parameter in calculations
        return (fahrenheit - 32) * 5.0 / 9.0;
    }

    public static void main(String[] args) {
        // Arguments: 10.0 and 5.0
        double area = triangleArea(10.0, 5.0);
        System.out.println("Area: " + area);  // 25.0

        // Argument: 98.6
        double bodyTemp = toCelsius(98.6);
        System.out.println("Body temp in C: " + bodyTemp);  // 37.0

        // Arguments can be variables too
        double b = 8.0;
        double h = 6.0;
        double area2 = triangleArea(b, h);  // b and h are arguments here
    }
}

Common Errors and Debugging

Forgetting Parentheses for No-Parameter Methods

Methods always need parentheses when called, even with no parameters:

</>Java
String text = "Hello";

// ERROR: length is not a variable
int len = text.length;  // Won't compile

// CORRECT: length() is a method
int len = text.length();  // Returns 5

This is a common mistake. No parentheses means you are looking for a variable, not calling a method.

Mismatched Parameter Types

The argument types must match (or be convertible to) the parameter types, in the right order:

</>Java
public static void printAge(String name, int age) {
    System.out.println(name + " is " + age);
}

// ERROR: Wrong order - int then String

printAge(25, "Alice");  // Won't compile

// ERROR: Wrong type - String instead of int

printAge("Alice", "25");  // Won't compile

// CORRECT: String then int
printAge("Alice", 25);  // Works

// This works - int automatically converts to double

public static void printPrice(double price) {
    System.out.println("$" + price);
}
printPrice(10);  // Prints $10.0

Using Return Values Incorrectly

Keep the difference between void and non-void methods straight:

</>Java
// Void method - performs action, no return value

public static void sayHello(String name) {
    System.out.println("Hello, " + name);
}

// Non-void method - returns a value

public static String makeGreeting(String name) {
    return "Hello, " + name;
}

// ERROR: Can't store void method result
String message = sayHello("Bob");  // Won't compile

// CORRECT: Call void method as statement
sayHello("Bob");  // Prints "Hello, Bob"

// CORRECT: Store non-void method result
String greeting = makeGreeting("Bob");  // greeting = "Hello, Bob"

// Legal but pointless - ignoring return value

makeGreeting("Bob");  // Calculates but doesn't use result

How to Use This on the AP Computer Science A Exam

MCQ

Expect questions that give you several method definitions and ask which call is valid. Check the method name, then the number, order, and types of arguments. Watch for overloaded methods that share a name but differ in their parameter lists, and remember that an int argument can be accepted where a double parameter is expected.

Code Tracing

When you trace a call, remember that the program jumps into the method, runs its statements, and then returns to the line right after the call. Arguments are passed by value, so the method works with copies. Use the return value only for non-void methods.

Free Response

When you write methods for free-response code writing, match the requested signature exactly: same method name, same parameter types in the same order, and the correct return type. A method that returns a value needs a return statement of the matching type, while a void method should not try to return one.

Common Trap

Storing the result of a void method, missing the empty parentheses on a no-parameter call, or swapping argument order are all quick ways to lose points. Slow down and verify each call against the method's signature.

Common Misconceptions

  • The return type is part of the signature. It is not. Only the method name and ordered parameter types make up the signature, which is why two methods cannot differ by return type alone.
  • Parameters and arguments are the same thing. Parameters are the variables in the method header; arguments are the actual values you pass in when you call the method.
  • No-parameter methods do not need parentheses. They do. Without parentheses you are referencing a variable, not calling the method.
  • Void methods return something you can store. They do not return a value, so trying to assign their "result" to a variable will not compile.
  • Java passes the original variable into a method. Java uses call by value, so the method receives a copy of each argument.
  • Order of arguments does not matter as long as the types are present. Order matters; arguments must line up with the parameter list by position and type.

Vocabulary

The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.

Term

Definition

argument

A value or variable passed to a method or constructor when it is called.

call by value

A method of passing arguments where the parameters are initialized with copies of the argument values rather than references to the original values.

constructor

A special method that is called to create and initialize an object of a class, having the same name as the class.

flow of control

The order in which statements in a program are executed, which can be interrupted by method calls and resumed after the method completes.

method

A named block of code that only runs when it is called, allowing programmers to reuse code and organize programs into logical sections.

method call

An invocation of a method that interrupts sequential execution and causes the program to execute the method's statements before returning control to the calling location.

method signature

The combination of a method's name and its ordered list of parameter types, used to identify and call a specific method.

non-void method

A method that returns a value of a specified type that can be stored in a variable or used as part of an expression.

overloaded method

Multiple methods with the same name but different method signatures, allowing the same method name to be used with different parameter types or numbers.

parameter

A variable declared in the header of a method or constructor that receives values passed to the method when it is called.

parameter list

The list of parameters in a method signature that specifies the types and order of arguments the method expects.

procedural abstraction

The ability to use a method by knowing what it does without needing to understand how it was implemented.

return statement

A statement that terminates method execution and returns control flow to the point immediately following where the method was called.

return value

The value produced by a non-void method that matches the return type specified in the method header.

void method

A method that does not return a value and cannot be used as part of an expression.

Frequently Asked Questions

What is a method signature in AP CSA?

A method signature is the method name plus the ordered list of parameter types. The return type is not part of the signature, so two methods cannot differ only by return type.

What is the difference between parameters and arguments?

Parameters are variables declared in a method header. Arguments are the actual values passed into the method call. The arguments must match the parameters in number, order, and compatible type.

How do you call a public void method in Java?

Call a void method as a standalone statement using the method name and arguments in parentheses. If it belongs to an object, use objectName.methodName(arguments). Since it is void, do not store it in a variable or use it in an expression.

What is method overloading?

Methods are overloaded when they have the same name but different signatures. That means the parameter type list must differ by number, order, or type.

What does call by value mean in Java?

Call by value means Java initializes method parameters with copies of the argument values. The method can use those copies, but it does not receive the original primitive variable itself.

What is the most common AP CSA method-call mistake?

Common mistakes include forgetting parentheses on a no-parameter method, swapping argument order, storing the result of a void method, or ignoring the return value of a non-void method.

Pep mascot
Upgrade your Fiveable account to print any study guide

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Click below to go to billing portal → update your plan → choose Yearly→ and select "Fiveable Share Plan". Only pay the difference

Plan is open to all students, teachers, parents, etc
Pep mascot
Upgrade your Fiveable account to export vocabulary

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Plan is open to all students, teachers, parents, etc
report an error
description

screenshots help us find and fix the issue faster (optional)

add screenshot