• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Complex class hierarchies often need to combine multiple inheritance patterns — both hierarchical and multiple inheritance simultaneously. A class might extend a parent class while implementing multiple interfaces, creating a hybrid structure. Without a safe way to do this, complex type hierarchies would be impossible.

Core Idea

Hybrid Inheritance is a combination of two or more types of inheritance. In Java, this is achievable only through interfaces. For example, a class may implement two interfaces that themselves extend a base interface, while the class also extends a parent class. The diamond problem is avoided because interfaces provide no conflicting state resolution — the class always wins over interface defaults.

How It Works

In hybrid inheritance: Interface1 and Interface2 extend BaseInterface. A class C extends ParentClass and implements Interface1, Interface2. The class inherits behavior from both the class hierarchy (via extends) and the interface hierarchy (via implements). Java’s rule is: class implementation always takes priority over interface default methods, preventing ambiguity. The result is a combination of multilevel (via the class chain) and multiple (via interfaces) inheritance.

Visual Explanation

hybrid_inheritance BaseI Base Interface I1 Interface A I1->BaseI extends I2 Interface B I2->BaseI extends Parent Parent Class Child Class C extends Parent implements A, B Child->I1 implements Child->I2 implements Child->Parent extends

Semantic Network

semantic_hybrid_inheritance THIS Hybrid Inheritance MULTI Multiple Inheritance THIS--MULTI built from INTER Interfaces THIS--INTER built from INHER Inheritance THIS--INHER related

Key Properties

  • Combination of types: Merges two or more inheritance types (e.g., multilevel + multiple)
  • Interface-only in Java: Like multiple inheritance, hybrid is achievable only through interfaces
  • Class-before-interface rule: Concrete class implementation always beats interface default methods
  • Most complex form: Overuse leads to unmaintainable class hierarchies
  • No state diamond problem: Since only interfaces provide the multiple aspect, state conflicts are impossible

Connections

Edge Cases & Gotchas

  • Complexity: Hybrid inheritance is the most complex form — overuse leads to unmaintainable hierarchies
  • Method resolution order: Java uses class-before-interface rule: the concrete class’s implementation beats any default method