Are defaults in JDK 8 a form of multiple inheritance in Java? Are defaults in JDK 8 a form of multiple inheritance in Java? java java

Are defaults in JDK 8 a form of multiple inheritance in Java?


The answer to the duplicate operation is:

To solve multiple inheritance issue a class implementing two interfaces providing a default implementation for the same method name and signature must provide an implementation of the method. [Full Article]

My answer to your question is: Yes, it is a form of multiple inheritance, because you can inherit behavior from different parents. What's missing is to inherit states, i. e., attributes.


I know this is a old post, but as i'm working with this stuff...

You will have an error from the compiler, telling you that:

 class TimeTravelingStudent inherits unrelated defaults for present() from types Attendance and Timeline reference to present is ambiguous, both method present() in Timeline and method present() in Attendance match.


There are two scenarios:

1) First, that was mentioned, where there is no most specific interface

public interface A {   default void doStuff(){ /* implementation */ }}public interface B {   default void doStuff() { /* implementation */ } }public class C implements A, B {// option 1: own implementation// OR// option 2: use new syntax to call specific interface or face compilation error  void doStuff(){      B.super.doStuff();  }}

2) Second, when there IS a more specific interface:

   public interface A {       default void doStuff() { /* implementation */ }     }    public interface B extends A {       default void doStuff() { /* implementation */ }     }    public class C implements A, B {    // will use method from B, as it is "closer" to C    }