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

# 8.4.7. Method Body

A *method body* is either a block of code that implements the method or simply a semicolon, indicating the lack of an implementation.

```
MethodBody:
  Block
  ;
```

The body of a method must be a semicolon if the method is `abstract` or `native` ([§8.4.3.1](8.4.3.1.md), [§8.4.3.4](8.4.3.4.md)). More precisely:

- It is a compile-time error if a method declaration is either `abstract` or `native` and has a block for its body.
- It is a compile-time error if a method declaration is neither `abstract` nor `native` and has a semicolon for its body.

If an implementation is to be provided for a method declared `void`, but the implementation requires no executable code, the method body should be written as a block that contains no statements: "`{ }`".

The rules for `return` statements in a method body are specified in [§14.17](14.17.md).

If a method is declared to have a return type ([§8.4.5](8.4.5.md)), then a compile-time error occurs if the body of the method can complete normally ([§14.1](14.1.md)).

In other words, a method with a return type must return only by using a `return` statement that provides a value return; the method is not allowed to "drop off the end of its body". See [§14.17](14.17.md) for the precise rules about `return` statements in a method body.

It is possible for a method to have a return type and yet contain no `return` statements. Here is one example:

```
class DizzyDean {
    int pitch() { throw new RuntimeException("90 mph?!"); }
}
```
