---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 8 Edition"
java_version: 8
chapter: "Chapter 15. Expressions"
section: "15.12.4.3"
heading: "15.12.4.3. Check Accessibility of Type and Method"
parent: "15.12.4. Run-Time Evaluation of Method Invocation"
source: https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.4.3
id: "15.12.4.3"
url: https://jvm.obfuscated.software/jls/se8/15.12.4.3.html
raw: https://jvm.obfuscated.software/jls/se8/15.12.4.3.md
---

# 15.12.4.3. Check Accessibility of Type and Method

Let C be the class containing the method invocation, and let T be the qualifying type of the method invocation ([§13.1](13.1.md)), and let `m` be the name of the method as determined at compile time ([§15.12.3](15.12.3.md)).

An implementation of the Java programming language must ensure, as part of linkage, that the method `m` still exists in the type T. If this is not true, then a `NoSuchMethodError` (which is a subclass of `IncompatibleClassChangeError`) occurs.

If the invocation mode is `interface`, then the implementation must also check that the target reference type still implements the specified interface. If the target reference type does not still implement the interface, then an `IncompatibleClassChangeError` occurs.

The implementation must also ensure, during linkage, that the type T and the method `m` are accessible:

- For the type T:

  - If T is in the same package as C, then T is accessible.
  - If T is in a different package than C, and T is `public`, then T is accessible.
  - If T is in a different package than C, and T is `protected`, then T is accessible if and only if C is a subclass of T.

- For the method `m`:

  - If `m` is `public`, then `m` is accessible. (All members of interfaces are `public` ([§9.2](9.2.md)).)
  - If `m` is `protected`, then `m` is accessible if and only if either T is in the same package as C, or C is T or a subclass of T.
  - If `m` has package access, then `m` is accessible if and only if T is in the same package as C.
  - If `m` is `private`, then `m` is accessible if and only if C is T, or C encloses T, or T encloses C, or T and C are both enclosed by a third class.

If either T or `m` is not accessible, then an `IllegalAccessError` occurs ([§12.3](12.3.md)).
