Multiple Inheritance Ambiguity with Interface

前端 未结 6 2202
轮回少年
轮回少年 2020-12-24 12:48

We all know about the diamond problem regarding multiple inheritance -

   A
  / \\
 B   C
  \\ / 
   D

This problem describe an ambiguous

6条回答
  •  不思量自难忘°
    2020-12-24 13:44

    With default methods in interface introduced in Java 8, multiple inheritance related problem may arise, there are 3 scenarios -

    1- If implementing class overrides the default method and provides its own functionality for the default method then the method of the class takes priority over the interface default methods.

    2-When class implements both interfaces and both have the same default method, also the class is not overriding that method then the error will be thrown.

    3-In case when an interface extends another interface and both have the same default method, the inheriting interface default method will take precedence.

    read more about it here.

提交回复
热议问题