Learn Java with Projects by Dr. Seán Kennedy and Maaike van Putten
Author:Dr. Seán Kennedy and
Maaike van Putten
Language: eng
Format: epub
Publisher: Packt Publishing Pvt. Ltd.
Published: 2023-11-27T00:00:00+00:00
Multiple interface inheritance
The Diamond of Death (https://en.wikipedia.org/wiki/Multiple_inheritance#:~:text=The%20âdiamond%20problemâ%20(sometimes,from%20both%20B%20and%20C) arises when a class finds that it has inherited two methods of the same name; which one should it work with? This was a concern in C++, where multiple-class inheritance is allowed and was an influencing factor in prohibiting multiple-class inheritance in Java.
However, Java has always allowed a class to implement multiple interfaces. However, now that Java 8 allows default methods, which have code bodies that are inheritable, is it not possible for Java 8 to encounter a âDiamond of Deathâ scenario? Couldnât a class implement two (or more) interfaces that have the same default methods? What happens then? The good news is that the compiler steps in and forces your class to override the âoffendingâ default method.
So, that just leaves the question, what if we wanted to access each of the default methods? For example, letâs assume we have a default method called foo() in interface A and a default method called foo() in interface B. What if, in our class, we wanted to execute the three different versions of foo() â the one from A, the one from B, and the one from our class that the compiler forced us to create?
Figure 10.7 shows how to do this in code:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ajax | Assembly Language Programming |
Borland Delphi | C & C++ |
C# | CSS |
Compiler Design | Compilers |
DHTML | Debugging |
Delphi | Fortran |
Java | Lisp |
Perl | Prolog |
Python | RPG |
Ruby | Swift |
Visual Basic | XHTML |
XML | XSL |
Deep Learning with Python by François Chollet(11974)
Hello! Python by Anthony Briggs(9420)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9386)
The Mikado Method by Ola Ellnestam Daniel Brolund(9350)
Dependency Injection in .NET by Mark Seemann(8895)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7893)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7410)
Grails in Action by Glen Smith Peter Ledbrook(7330)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7158)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6003)
Kotlin in Action by Dmitry Jemerov(4682)
Practical Vim (for Kathryn Amaral) by Drew Neil(3746)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3623)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3525)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3275)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(3169)
Microservices with Go by Alexander Shuiskov(2953)
Learning Java by Patrick Niemeyer & Daniel Leuck(2889)
Practical Design Patterns for Java Developers by Miroslav Wengner(2871)