Java does not support multiple inheritance of classes, and standard methods do not circumvent this restriction, as classes can maintain state (with instance variables), but interfaces cannot.
Default methods provide a limited form of multiple inheritance of behavior, allowing a class to inherit behaviors from multiple interfaces with default methods.
Conflicts can occur when two interfaces implemented by a class have the same default method, as in the case of two interfaces, Alpha and Beta, both with the reset() method.
Rules for resolving conflicts:
1 The class implementation takes priority over the default interface implementation.
2 If two interfaces have the same default method and the class does not override the method, an error will occur.
3 If one interface inherits another and both define the same default method, the version of the inherited interface takes precedence.
To explicitly reference a standard implementation of an interface, you can use the syntax: NameInterface.super.NameMethod().
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3