# AP® Computer Science A 1.9 Method Signatures

Source: https://lockincs.com/ap-csa/unit-1/1-9-method-signatures/  
Last reviewed against the College Board Course and Exam Description (CED): 2026-11-12  
CED codes: 1.9.A, 1.9.A.1, 1.9.A.2, 1.9.B, 1.9.B.1, 1.9.B.2, 1.9.B.3, 1.9.B.4, 1.9.B.5

A method is a named block of code that runs only when it is called. Its signature is the method name plus the ordered list of parameter types, and arguments in a call must match those types in number and order. Arguments are passed by call by value, and methods with the same name but different signatures are overloaded.

## What you will learn

- 1.9.A Identify the correct method to call based on documentation and method signatures.
- 1.9.B Describe how to call methods.

## 1\. Methods and procedural abstraction

A **method** is a named block of code that only runs when it is called. A **block** is any section of code enclosed in braces `{ }` 1.9.A.1.

**Procedural abstraction** allows a programmer to use a method by knowing what the method does, even without knowing how it was written 1.9.A.1. You call `Math.sqrt(16.0)` without ever seeing its code.

## 2\. Parameters and method signatures

A **parameter** is a variable declared in the header of a method or constructor. It can be used inside the body of the method, and it lets values (arguments) be passed in and used by the method 1.9.A.2.

A **method signature** for a method with parameters is the method name plus the ordered list of parameter types. For a method without parameters, the signature is the method name plus an empty parameter list, for example `getHeight()` 1.9.A.2.

Reading a method header, part by part:

```
// not runnable: a method header from the Java Quick Reference
public static double pow(double base, double exponent)
```

| Part of the header | Meaning |
| --- | --- |
| `static` | a class method (topic 1.10) |
| `double` (before `pow`) | the return type: the type of value sent back |
| `pow` | the method name |
| `(double base, double exponent)` | the parameter list: the type and name of each parameter |
| `pow(double, double)` | the signature: name + ordered parameter types |

Same name, different signatures means overloaded methods (section 5).

## 3\. Calling void and non-void methods

A **void method** does not have a return value, so it is not called as part of an expression 1.9.B.1. `p.grow(5);` is fine as a statement on its own.

```
// does not compile
Plant p = new Plant("Fern", 30);
int h = p.grow(5);
```

Real view:

```
error: incompatible types: void cannot be converted to int
```

A **non-void method** returns a value of the same type as the return type in its header. To use the returned value, store it in a variable or use it as part of an expression 1.9.B.2.

```
Plant p = new Plant("Fern", 30);
p.grow(5);                   // void: a statement on its own
int h = p.getHeight();       // non-void: value stored
System.out.println(h);
System.out.println(p.getHeight() * 2);   // value used in an expression
```

Output:

```
35
70
```

## 4\. Arguments and call by value

An **argument** is a value passed into a method when the method is called. Arguments must be compatible in number and order with the types in the parameter list of the method signature. An `int` argument can go to a `double` parameter, as in `Math.pow(2, 10)`, because the `int` is widened (topic 1.5). Arguments are passed using **call by value**: each parameter is initialized with a copy of the argument 1.9.B.3. Changing the parameter inside the method does not change the caller’s variable.

```
public static void addTen(int value)
{
    value = value + 10;
    System.out.println("Inside: " + value);
}

// in main
int score = 5;
addTen(score);
System.out.println("Outside: " + score);
```

Output:

```
Inside: 15
Outside: 5
```

`value` gets a copy of 5 and becomes 15, but `score` in `main` is still 5. The copy disappears when the method ends.

## 5\. Overloaded methods

Methods are **overloaded** when there are several methods with the same name but different signatures 1.9.B.4, for example `abs(int x)` and `abs(double x)`. Java picks the method whose parameter types match the arguments, in order.

```
public static void show(int points)
{
    System.out.println("Points: " + points);
}

public static void show(String player, int points)
{
    System.out.println(player + ": " + points);
}

public static void show(int points, String player)
{
    System.out.println(points + " for " + player);
}

// in main
show(12);
show("Ana", 12);
show(12, "Ana");
```

Output:

```
Points: 12
Ana: 12
12 for Ana
```

Two methods with the same name and the same parameter types do not compile, even if the parameter names differ:

```
// does not compile
public static int area(int side) { return side * side; }
public static int area(int length) { return length * length; }

// in main
System.out.println(area(3));
```

Real view:

```
error: method area(int) is already defined in class Main
```

> **Background (not tested): exact matches win.** When one overload matches the argument types exactly, Java uses it, so `Math.abs(-4)` uses `abs(int)` and returns the `int` 4, while `Math.abs(-4.0)` uses `abs(double)` and returns 4.0.

```
System.out.println(Math.abs(-4));
System.out.println(Math.abs(-4.0));
```

Output:

```
4
4.0
```

## 6\. Flow of control in a method call

A method call interrupts the sequential execution of statements. The program first runs the statements in the method. Once the last statement in the method has run, or a `return` statement runs, the flow of control returns to the point right after the call 1.9.B.5.

```
public static void greet()
{
    System.out.println("  inside greet");
}

// in main
System.out.println("before");
greet();
System.out.println("after");
```

Output:

```
before
  inside greet
after
```

Arguments are worked out before the call, so nested calls run inside out. In `Math.sqrt(Math.abs(-16))`, `Math.abs(-16)` runs first and gives 16, then `Math.sqrt(16)` gives 4.0.

```
System.out.println(Math.sqrt(Math.abs(-16)));
```

Output:

```
4.0
```

## Common mix-ups

- Not true: The return type is part of the method signature. The signature is only the method name and the ordered list of parameter types. The return type and the parameter names are not part of it.
- Not true: Changing a parameter inside a method changes the caller's variable. Call by value: the parameter gets a copy of the argument. Changing the copy does not change the caller's variable.
- Not true: You can store the result of a void method in a variable. A void method returns no value, so it cannot be used in an expression. int h = p.grow(5); does not compile.
- Not true: Two methods can share a name if their parameter names differ. Overloaded methods need different parameter types (or a different number or order of types). Same name and same parameter types do not compile, even with different parameter names.

## In 30 seconds

- A method is a named block of code that only runs when called; a block is code inside braces.
- Procedural abstraction: use a method by knowing what it does, not how it was written.
- A parameter is a variable in a method or constructor header; the signature is the name plus the ordered parameter types.
- A void method returns nothing and is not used in an expression; a non-void method's value must be stored or used in an expression.
- Arguments must match the parameter types in number and order; call by value gives the parameters copies.
- Overloaded methods share a name but have different signatures; a call runs the method, then returns to the point right after the call.

## Checkpoint: 4 practice questions

### Question 1

A class has these three methods. Which call runs the third method?

```java
public void show(int points)
public void show(String player, int points)
public void show(int points, String player)
```

- A. `show("Ana", 12);`
- B. `show(12);`
- C. `show(12, "Ana");`
- D. `show(12, 12);`

**Answer: C.** The signature `show(int, String)` matches the argument types in order: int, then String. A matches the second method, `show(String, int)`. B matches the first method. D matches no method, because no version takes two ints, so it does not compile.

### Question 2

Consider the following method and code segment in the same class. What is printed?

```java
public static void doubleIt(int n)
{
    n = n * 2;
}

// in main
int count = 7;
doubleIt(count);
System.out.println(count);
```

- A. 14
- B. 9
- C. Nothing; the code does not compile.
- D. 7

**Answer: D.** Call by value: `n` gets a copy of 7. Doubling the copy does not change `count`. A assumes the change to `n` reaches `count`. B adds 2 instead of doubling. C is wrong because calling a void method as a statement on its own is correct.

### Question 3

Which of the following is the method signature of `public double average(int total, int count)`?

- A. `average(int, int)`
- B. `double average(int, int)`
- C. `average(total, count)`
- D. `average(int total, int count)`

**Answer: A.** A method signature is the method name plus the ordered list of parameter types. B wrongly includes the return type. C lists parameter names instead of types. D includes the parameter names, which are not part of the signature.

### Question 4

Consider the following method and code segment in the same class. What is printed?

```java
public static int triple(int n)
{
    System.out.print("T");
    return n * 3;
}

// in main
int x = triple(2) + triple(1);
System.out.println(x);
```

- A. `9`
- B. `TT9`
- C. `T9`
- D. Nothing; `triple` cannot be used in an expression.

**Answer: B.** Each call pauses `main`, runs the method (printing T), and returns its value: 6 and 3. Then 9 is printed, so the output is TT9. A forgets that each call prints. C counts only one call. D is wrong because a non-void method's return value can be used in an expression.

## Questions students ask

**What is a method signature in Java?**

A method signature is the method name plus the ordered list of parameter types, such as pow(double, double). A method with no parameters has the name and an empty list, such as getHeight().

**What is the difference between a parameter and an argument?**

A parameter is a variable declared in the method header. An argument is the value passed in when the method is called. The parameter is initialized with a copy of the argument.

**What does call by value mean?**

Each parameter is initialized with a copy of the argument. Changing the parameter inside the method does not change the caller's variable.

**What are overloaded methods?**

Overloaded methods have the same name but different signatures, such as abs(int x) and abs(double x). Java chooses the one whose parameter types match the arguments.

**Can you call a void method inside an expression?**

No. A void method returns no value, so it is called as a statement on its own, such as p.grow(5);.

---

© LockInCS, licensed CC BY-NC-ND 4.0. AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this website.
