Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › OOP II — Inheritance, Polymorphism, Interfaces

Since Java 8 interfaces can have default methods. Why were they added, and how is the diamond conflict resolved?

Level II · JuniorOOP II — Inheritance, Polymorphism, Interfaces
Short answer

Default methods were added to let interfaces evolve without breaking existing implementors — that's how Collection got stream() and forEach() without breaking every implementation.

Explanation

If a class inherits conflicting default methods from two interfaces (the diamond problem), the compiler forces you to override and disambiguate explicitly, calling InterfaceName.super.method() to pick one. Class methods always win over interface defaults, and a more specific subinterface's default wins over its parent's.

Common mistakes
  • Thinking default methods make interfaces the same as abstract classes.
  • Not knowing a class must override to resolve a diamond conflict.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for OOP II — Inheritance, Polymorphism, Interfaces.

Practise free

More on OOP II — Inheritance, Polymorphism, Interfaces