# Methods

Source: https://cca.twango.dev/AP-Computer-Science/methods

# Methods

## Definition

This method prints `Hi!` and returns `0`:

```java
public int hello() {
    System.out.println("Hi!");
    return 0;
}
```

It belongs inside a class. General schematic syntax:

```text
accessModifier returnType name(parameters) {
    body
}
```

The declared return type determines the allowed return value; `void` means no value is returned.

> [!note] Terminology clarification
> A method's signature includes its name and parameter types, not its return type. Thus changing only the return type cannot create an overload.

Source: [Java Language Specification §8.4.2](https://docs.oracle.com/javase/specs/jls/se17/html/jls-8.html#jls-8.4.2).

Related: [[object-oriented-programming|Classes and overloading]] · [[recursion|Recursion]]
