---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 20 Edition"
java_version: 20
chapter: "Chapter 8. Classes"
section: "8.4"
heading: "8.4. Method Declarations"
parent: "Chapter 8. Classes"
source: https://docs.oracle.com/javase/specs/jls/se20/html/jls-8.html#jls-8.4
id: "8.4"
url: https://jvm.obfuscated.software/jls/se20/8.4.html
raw: https://jvm.obfuscated.software/jls/se20/8.4.md
---

# 8.4. Method Declarations

A *method* declares executable code that can be invoked, passing a fixed number of values as arguments.

```
MethodDeclaration:
  {MethodModifier} MethodHeader MethodBody

MethodHeader:
  Result MethodDeclarator [Throws]
  TypeParameters {Annotation} Result MethodDeclarator [Throws]

MethodDeclarator:
  Identifier ( [ReceiverParameter ,] [FormalParameterList] ) [Dims]

ReceiverParameter:
  {Annotation} UnannType [Identifier .] this
```

The following production from [§4.3](4.3.md) is shown here for convenience:

```
Dims:
  {Annotation} [ ] {{Annotation} [ ]}
```

The *FormalParameterList* clause is described in [§8.4.1](8.4.1.md), the *MethodModifier* clause in [§8.4.3](8.4.3.md), the *TypeParameters* clause in [§8.4.4](8.4.4.md), the *Result* clause in [§8.4.5](8.4.5.md), the *Throws* clause in [§8.4.6](8.4.6.md), and the *MethodBody* in [§8.4.7](8.4.7.md).

The *Identifier* in a *MethodDeclarator* may be used in a name to refer to the method ([§6.5.7.1](6.5.7.1.md), [§15.12](15.12.md)).

The scope and shadowing of a method declaration is specified in [§6.3](6.3.md) and [§6.4.1](6.4.1.md).

The *receiver parameter* is an optional syntactic device for an instance method or an inner class's constructor. For an instance method, the receiver parameter represents the object for which the method is invoked. For an inner class's constructor, the receiver parameter represents the immediately enclosing instance of the newly constructed object. In both cases, the receiver parameter exists solely to allow the type of the represented object to be denoted in source code, so that the type may be annotated ([§9.7.4](9.7.4.md)). The receiver parameter is not a formal parameter; more precisely, it is not a declaration of any kind of variable ([§4.12.3](4.12.3.md)), it is never bound to any value passed as an argument in a method invocation expression or class instance creation expression, and it has no effect whatsoever at run time.

A receiver parameter may appear either in the *MethodDeclarator* of an instance method or in the *ConstructorDeclarator* of a constructor of an inner class where the inner class is not declared in a static context ([§8.1.3](8.1.3.md)). If a receiver parameter appears in any other kind of method or constructor, then a compile-time error occurs.

The type and name of a receiver parameter are constrained as follows:

- In an instance method, the type of the receiver parameter must be the class or interface in which the method is declared, and the name of the receiver parameter must be `this`; otherwise, a compile-time error occurs.
- In an inner class's constructor, the type of the receiver parameter must be the class or interface which is the immediately enclosing type declaration of the inner class, and the name of the receiver parameter must be *Identifier* `.` `this` where *Identifier* is the simple name of the class or interface which is the immediately enclosing type declaration of the inner class; otherwise, a compile-time error occurs.

It is a compile-time error for the body of a class declaration to declare as members two methods with override-equivalent signatures ([§8.4.2](8.4.2.md)).

The declaration of a method that returns an array is allowed to place some or all of the bracket pairs that denote the array type after the formal parameter list. This syntax is supported for compatibility with early versions of the Java programming language. It is very strongly recommended that this syntax is not used in new code.

**Sections:**

- [8.4.1. Formal Parameters](8.4.1.md)
- [8.4.2. Method Signature](8.4.2.md)
- [8.4.3. Method Modifiers](8.4.3.md)
- [8.4.4. Generic Methods](8.4.4.md)
- [8.4.5. Method Result](8.4.5.md)
- [8.4.6. Method Throws](8.4.6.md)
- [8.4.7. Method Body](8.4.7.md)
- [8.4.8. Inheritance, Overriding, and Hiding](8.4.8.md)
- [8.4.9. Overloading](8.4.9.md)
