01 / 21

Method
Signatures

Learn how to read, write, and interpret the blueprint of every Java method: its access modifier, return type, name, and parameter list.

AP Computer Science A

What Is a Method?

A method is a named block of code that performs a specific task. Think of it like a recipe: it has a name, a list of ingredients (parameters), and produces a result (return value).

Reusable
Write once, call many times from different parts of your program.
Organized
Break complex programs into smaller, manageable pieces.
Testable
Each method can be tested and debugged independently.

What Is a Method Signature?

A method signature is the unique identity of a method. In Java, the signature consists of the method name and the ordered list of parameter types. The compiler uses signatures to distinguish one method from another.

Anatomy of a Method Header

public static int addNumbers ( int a , int b ) Access Modifier (optional keyword) Return Type Method Name Parameters Signature = Name + Parameter Types

The Five Parts of a Method Header

1
Access Modifier: Controls visibility: public, private, or protected.
2
Optional Keywords: static (class-level) or final (cannot be overridden).
3
Return Type: The data type of the value returned, or void if nothing is returned.
4
Method Name: A descriptive identifier following camelCase convention.
5
Parameter List: Zero or more typed variables in parentheses, separated by commas.

Return Types Explained

Every method must declare what type of value it returns. If the method performs an action without returning data, use void.

int
Returns a whole number. Must include a return statement.
double
Returns a decimal number like 3.14 or 0.5.
boolean
Returns true or false for conditional checks.
void
Returns nothing. Used for actions like printing output.

Parameters vs Arguments

Parameters
Variables declared in the method header. They act as placeholders for values the method will receive.
Arguments
The actual values passed to the method when it is called. They fill in the parameter placeholders.
// "int a" and "int b" are PARAMETERS public int add(int a, int b) { return a + b; } // 5 and 3 are ARGUMENTS int result = add(5, 3);

Signature vs Header: Key Distinction

Method Signature Method Header
Includes Name? ✓ Yes ✓ Yes
Includes Param Types? ✓ Yes ✓ Yes
Includes Param Names? ✕ No ✓ Yes
Includes Return Type? ✕ No ✓ Yes
Includes Access Modifier? ✕ No ✓ Yes
Used for Overloading? ✓ Yes ✕ No

How to Read a Method Signature

1
Identify the method name: What action does this method perform? Look for the camelCase identifier before the parentheses.
2
Count the parameters: How many inputs does it need? Count items separated by commas inside the parentheses.
3
Note each parameter type: What kind of data does each parameter accept? The type (int, String, double) comes before each name.
4
Check the return type: What does the method give back? This is NOT part of the signature, but essential for calling the method correctly.

Example 1: void Method

public void greet(String name) { System.out.println("Hello, " + name + "!"); }
Access
public: callable from anywhere
Return
void: no value returned
Name
greet: describes the action
Params
One String parameter called name

Example 2: Method with Return Value

public double calculateArea(double length, double width) { return length * width; }
Return Type
double: returns a decimal value
Parameters
Two doubles: length and width

Example 3: Method Overloading

// Signature: print(String) public void print(String msg) { System.out.println(msg); } // Signature: print(String, int) public void print(String msg, int times) { for (int i = 0; i < times; i++) System.out.println(msg); }

static vs Non-static Methods

static Methods
Belong to the class, not an instance. Called with the class name: Math.sqrt(25). Cannot access instance variables.
Non-static Methods
Belong to an object (instance). Called on an object: myDog.bark(). Can access instance variables.

Access Modifiers in Detail

Modifier Same Class Same Package Subclass Everywhere
public ✓ ✓ ✓ ✓
protected ✓ ✓ ✓ ✕
(default) ✓ ✓ ✕ ✕
private ✓ ✕ ✕ ✕

Common Mistakes to Avoid

✕ Including Return Type in Signature
The signature is only the method name and parameter types. Return type is part of the header, not the signature.
✕ Overloading by Return Type Alone
Two methods with the same name and parameters but different return types cause a compiler error.
✕ Confusing Parameters and Arguments
Parameters are in the definition; arguments are the values passed during the call. Mixing these up leads to type mismatch errors.

Summary: Method Signature Cheat Sheet

Concept What It Means Example
Method Name The identifier for the method calculateArea
Parameter List Types and names of inputs (double l, double w)
Signature Name + parameter types only calculateArea(double, double)
Return Type Type of value returned double
Header Full declaration line public double calculateArea(...)
Overloading Same name, different signatures print(String) vs print(String, int)

Question 1 of 5

Which of the following is the method signature for this method header?

public static double average(int x, int y)

Question 2 of 5

Which of the following pairs of methods are correctly overloaded?

Question 3 of 5

In the call myObj.process("hello", 42), what are "hello" and 42?

Question 4 of 5

A method is declared as private void reset(). Which statement is true?

Question 5 of 5

Consider these two method headers:

public int compute(double x, int y)

public int compute(int y, double x)

Do these methods have different signatures?