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

# 8.4.8. Inheritance, Overriding, and Hiding

A class C *inherits* from its direct superclass type D all concrete methods `m` (both `static` and instance) for which all of the following are true:

- `m` is a member of D.
- `m` is `public`, `protected`, or declared with package access in the same package as C.
- No method declared in C has a signature that is a subsignature ([§8.4.2](8.4.2.md)) of the signature of `m` as a member of D.

A class C *inherits* from its direct superclass type and direct superinterface types all `abstract` and default ([§9.4](9.4.md)) methods `m` for which all of the following are true:

- `m` is a member of the direct superclass type or a direct superinterface type of C, known in either case as D.
- `m` is `public`, `protected`, or declared with package access in the same package as C.
- No method declared in C has a signature that is a subsignature ([§8.4.2](8.4.2.md)) of the signature of `m` as a member of D.
- No concrete method inherited by C from its direct superclass type has a signature that is a subsignature of the signature of `m` as a member of D.
- There exists no method `m'` that is a member of the direct superclass type or a direct superinterface type of C, D' (`m` distinct from `m'`, D distinct from D'), such that `m'` overrides from the class or interface of D' the declaration of the method `m` ([§8.4.8.1](8.4.8.1.md), [§9.4.1.1](9.4.1.1.md)).

A class does not inherit `private` or `static` methods from its superinterface types.

Note that methods are overridden or hidden on a signature-by-signature basis. If, for example, a class declares two `public` methods with the same name ([§8.4.9](8.4.9.md)), and a subclass overrides one of them, the subclass still inherits the other method.

**Example 8.4.8-1. Inheritance**

```
interface I1 {
    int foo();
}

interface I2 {
    int foo();
}

abstract class Test implements I1, I2 {}
```

Here, the `abstract` class `Test` inherits the `abstract` method `foo` from interface `I1` and also the `abstract` method `foo` from interface `I2`. The key question in determining the inheritance of `foo` from `I1` is: does the method `foo` in `I2` override "from `I2`" ([§9.4.1.1](9.4.1.1.md)) the method `foo` in `I1`? No, because `I1` and `I2` are not subinterfaces of each other. Thus, from the viewpoint of class `Test`, the inheritance of `foo` from `I1` is unfettered; similarly for the inheritance of `foo` from `I2`. Per [§8.4.8.4](8.4.8.4.md), class `Test` can inherit both `foo` methods; obviously it must be declared `abstract`, or else override both `abstract` `foo` methods with a concrete method.

Note that it is possible for an inherited concrete method to prevent the inheritance of an `abstract` or default method. (The concrete method will override the `abstract` or default method "from C", per [§8.4.8.1](8.4.8.1.md) and [§9.4.1.1](9.4.1.1.md).) Also, it is possible for one supertype method to prevent the inheritance of another supertype method if the former "already" overrides the latter - this is the same as the rule for interfaces ([§9.4.1](9.4.1.md)), and prevents conflicts in which multiple default methods are inherited and one implementation is clearly meant to supersede the other.

**Sections:**

- [8.4.8.1. Overriding (by Instance Methods)](8.4.8.1.md)
- [8.4.8.2. Hiding (by Class Methods)](8.4.8.2.md)
- [8.4.8.3. Requirements in Overriding and Hiding](8.4.8.3.md)
- [8.4.8.4. Inheriting Methods with Override-Equivalent Signatures](8.4.8.4.md)
