PrepGo

AP Computer Science A Practice Quiz: Method Signatures

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Test your understanding with short quizzes. This quiz has 14 questions to check your progress.

Question 1 of 14

According to the provided text, what is a method?

All Questions (14)

According to the provided text, what is a method?

A) A named block of code that only runs when it is called.

B) A variable that stores different types of data.

C) A conditional statement that controls program flow.

D) A data structure for organizing information.

Correct Answer: A

The content explicitly states, 'A method is a named block of code that only runs when it is called.'

What are the essential components of a method signature for a method that accepts parameters?

A) The method name and its return type.

B) The return type and the names of the parameter variables.

C) The method name and the ordered list of parameter types.

D) The method name and the number of lines of code it contains.

Correct Answer: C

The provided text specifies that 'A method signature for a method with parameters consists of the method name and the ordered list of parameter types.'

Which concept allows a programmer to use a method effectively just by knowing what it does, without needing to understand how its internal code is written?

A) Method Calling

B) Return Value Storage

C) Procedural Abstraction

D) Parameter Typing

Correct Answer: C

The content defines this concept directly: '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.'

When a non-void method is executed, what is true about the value it provides back to the caller?

A) The value is always an integer.

B) The value must be immediately printed to the screen.

C) The value's type matches the return type specified in the method's header.

D) The value is always null.

Correct Answer: C

As stated in the text, 'A non-void method returns a value that is the same type as the return type in the header.'

A programmer needs to find the sum of two integers. The available method signatures in the documentation are: I. `calculateSum(double num1, double num2)` II. `calculateSum(int a, int b)` III. `displaySum(int a, int b)` Which method signature should be chosen to perform the calculation?

A) I

B) II

C) III

D) Either I or II would be correct.

Correct Answer: B

To correctly call a method, the arguments provided must match the ordered list of parameter types in the signature. Since the programmer has two integers, the signature `calculateSum(int a, int b)` is the correct one to call.

According to the provided content, what are the two ways to utilize the value returned by a non-void method?

A) It is either automatically printed or discarded.

B) It must be converted to a string or an integer.

C) It must be stored in a variable or used as part of an expression.

D) It can only be used as a parameter for another method call.

Correct Answer: C

The text is explicit: 'To use the return value when calling a non-void method, it must be stored in a variable or used as part of an expression.'

What is the primary action required to make a method's block of code execute?

A) Defining its signature.

B) Writing documentation for it.

C) Declaring its return type.

D) Calling the method.

Correct Answer: D

The content states that a method 'only runs when it is called.' Therefore, calling it is the action that triggers its execution.

Consider a method with the signature `createGreeting(String name, int hour)`. Which of the following represents a correct method call based on this signature?

A) createGreeting("Alice")

B) createGreeting(14, "Bob")

C) String message = createGreeting("Charlie", 9);

D) createGreeting("David", "10")

Correct Answer: C

The method signature requires a String first and an integer second, in that specific order. Option C provides the correct types in the correct order and correctly demonstrates one way to use a non-void method's return value by storing it in a variable.

A programmer is using a math library and calls a method `Math.sqrt(25)`. The programmer knows this will return the square root of 25 but is unaware of the specific algorithm the method uses to calculate it. This is a direct application of which principle?

A) Return Type Matching

B) Procedural Abstraction

C) Method Signature Definition

D) Variable Storage

Correct Answer: B

This scenario perfectly matches the definition of procedural abstraction, which 'allows a programmer to use a method by knowing what the method does even if they do not know how the method was written.'

What key information helps a programmer distinguish between multiple methods that have the same name?

A) The length of the method's code.

B) The ordered list of parameter types.

C) The names of the variables used inside the method.

D) The date the method was written.

Correct Answer: B

The method signature, which consists of the method name and the ordered list of parameter types, is used to uniquely identify a method. When methods share a name, the parameter list is what differentiates them.

If a method is described as 'non-void', what does this fundamentally imply?

A) The method cannot have any parameters.

B) The method must be called at least once.

C) The method returns a value.

D) The method's code is very complex.

Correct Answer: C

The text explicitly defines a non-void method as one that 'returns a value that is the same type as the return type in the header.'

A non-void method `getUserID()` is called, but its return value is not assigned to a variable or used in another expression, as shown: `getUserID();`. What is the most likely outcome?

A) The program will fail to compile.

B) The method will not execute because its result has nowhere to go.

C) The method will execute, but its return value will be discarded and lost.

D) The program will halt with a runtime error.

Correct Answer: C

The text states that to *use* a return value, it must be stored or used in an expression. It does not forbid calling the method without capturing the value. The method call is valid, so it will run, but the value it returns is not captured and is therefore lost.

What is the primary role of the 'ordered list of parameter types' within a method signature?

A) It serves as a comment explaining the method's purpose.

B) It dictates the exact data types and sequence of arguments required for a valid method call.

C) It specifies the name of the variable that will store the method's return value.

D) It determines how much memory the method will use when it runs.

Correct Answer: B

The method signature acts as a strict contract for calling the method. The ordered list of parameter types defines exactly what kind of data, and in what order, must be provided for the call to be successful.

A programmer needs to retrieve a student's grade as a number to check if they passed. The documentation shows two available methods: 1. `public double getGrade(int studentID)` 2. `public void printGrade(int studentID)` Which method should be called and why?

A) `printGrade`, because it is a void method and simpler to call.

B) `getGrade`, because it is a non-void method that returns a value which can be stored and used for the pass/fail check.

C) Either method is acceptable, as they both accomplish the same task.

D) `printGrade`, because the student ID is an integer.

Correct Answer: B

The goal is to use the grade in a subsequent logical check (pass/fail). The `getGrade` method is non-void and returns a `double`. According to the text, this return value can be 'stored in a variable or used as part of an expression,' which is required for the check. The `printGrade` method is `void` and does not return a value that can be used later.