---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 11 Edition"
java_version: 11
chapter: "Chapter 5. Loading, Linking, and Initializing"
section: "5.4.6"
heading: "5.4.6. Method Selection"
parent: "5.4. Linking"
source: https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-5.html#jvms-5.4.6
id: "5.4.6"
url: https://jvm.obfuscated.software/jvms/se11/5.4.6.html
raw: https://jvm.obfuscated.software/jvms/se11/5.4.6.md
---

# 5.4.6. Method Selection

During execution of an *invokeinterface* or *invokevirtual* instruction, a method is *selected* with respect to (i) the run-time type of the object on the stack, and (ii) a method that was previously *resolved* by the instruction. The rules to select a method with respect to a class or interface C and a method `m_R` are as follows:

1. If `m_R` is marked `ACC_PRIVATE`, then it is the selected method.

2. Otherwise, the selected method is determined by the following lookup procedure:

   - If C contains a declaration of an instance method `m` that can override `m_R` ([§5.4.5](5.4.5.md)), then `m` is the selected method.

   - Otherwise, if C has a superclass, a search for a declaration of an instance method that can override `m_R` is performed, starting with the direct superclass of C and continuing with the direct superclass of that class, and so forth, until a method is found or no further superclasses exist. If a method is found, it is the selected method.

   - Otherwise, the maximally-specific superinterface methods of C are determined ([§5.4.3.3](5.4.3.3.md)). If exactly one matches `m_R`'s name and descriptor and is not `abstract`, then it is the selected method.

     Any maximally-specific superinterface method selected in this step can override `m_R`; there is no need to check this explicitly.

While C will typically be a class, it may be an interface when these rules are applied during preparation ([§5.4.2](5.4.2.md)).
