---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 17 Edition"
java_version: 17
chapter: "Chapter 6. Names"
section: "6.5.7"
heading: "6.5.7. Meaning of Method Names"
parent: "6.5. Determining the Meaning of a Name"
source: https://docs.oracle.com/javase/specs/jls/se17/html/jls-6.html#jls-6.5.7
id: "6.5.7"
url: https://jvm.obfuscated.software/jls/se17/6.5.7.html
raw: https://jvm.obfuscated.software/jls/se17/6.5.7.md
---

# 6.5.7. Meaning of Method Names

The meaning of a name classified as a *MethodName* is determined as follows.

## 6.5.7.1. Simple Method Names

A simple method name appears in the context of a method invocation expression ([§15.12](15.12.md)). The simple method name consists of a single *UnqualifiedMethodIdentifier* which specifies the name of the method to be invoked. The rules of method invocation require that the *UnqualifiedMethodIdentifier* denotes a method that is in scope at the point of the method invocation. The rules also prohibit ([§15.12.3](15.12.3.md)) a reference to an instance method occurring in a static context ([§8.1.3](8.1.3.md)), or in a nested class or interface other than an inner class of the class or interface which declares the instance method.

**Example 6.5.7.1-1. Simple Method Names**

The following program demonstrates the role of scoping when determining which method to invoke.

```
class Super {
    void f2(String s)       {}
    void f3(String s)       {}
    void f3(int i1, int i2) {}
}

class Test {
    void f1(int i) {}
    void f2(int i) {}
    void f3(int i) {}

    void m() {
        new Super() {
            {
                f1(0);  // OK, resolves to Test.f1(int)
                f2(0);  // compile-time error
                f3(0);  // compile-time error
            }
        };
    }
}
```

For the invocation `f1(0)`, only one method named `f1` is in scope. It is the method `Test.f1(int)`, whose declaration is in scope throughout the body of `Test` including the anonymous class declaration. [§15.12.1](15.12.1.md) chooses to search in class `Test` since the anonymous class declaration has no member named `f1`. Eventually, `Test.f1(int)` is resolved.

For the invocation `f2(0)`, two methods named `f2` are in scope. First, the declaration of the method `Super.f2(String)` is in scope throughout the anonymous class declaration. Second, the declaration of the method `Test.f2(int)` is in scope throughout the body of `Test` including the anonymous class declaration. (Note that neither declaration shadows the other, because at the point where each is declared, the other is not in scope.) [§15.12.1](15.12.1.md) chooses to search in class `Super` because it has a member named `f2`. However, `Super.f2(String)` is not applicable to `f2(0)`, so a compile-time error occurs. Note that class `Test` is not searched.

For the invocation `f3(0)`, three methods named `f3` are in scope. First and second, the declarations of the methods `Super.f3(String)` and `Super.f3(int,int)` are in scope throughout the anonymous class declaration. Third, the declaration of the method `Test.f3(int)` is in scope throughout the body of `Test` including the anonymous class declaration. [§15.12.1](15.12.1.md) chooses to search in class `Super` because it has a member named `f3`. However, `Super.f3(String)` and `Super.f3(int,int)` are not applicable to `f3(0)`, so a compile-time error occurs. Note that class `Test` is not searched.

Choosing to search a nested class's superclass hierarchy before the lexically enclosing scope is called the "comb rule" ([§15.12.1](15.12.1.md)).
