Hi. Why the answer "In Java 8, interfaces allow multiple implementation inheritance through default methods." is incorrec?
After all such code will be correct:
interface I1{
public default void m1(){
System.out.println("in I1.m1");
}
}
interface I2{
public default void m2(){
System.out.println("in I2.m1");
}
}
class CI implements I1, I2{
}
About Question enthuware.ocajp.i.v8.2.1479 :
Moderators: Site Manager, fjwalraven
-
- Posts: 8
- Joined: Wed Oct 25, 2017 2:53 am
- Contact:
-
- Site Admin
- Posts: 10061
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1479 :
You are right. The explanation is talking about a specific case of multiple implementation where implementation of the same method is inherited from multiple interfaces. In general, though Java does support a form of multiple implementation inheritance through default methods as given here: https://docs.oracle.com/javase/tutorial ... tance.html
This has now been updated.
thank you for your feedback!
Paul.
This has now been updated.
thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1479 :
In the answer to another question (in another test) you stated:
Now in this question you are saying that one of the correct answers is:However, Java 8 still does not allow a class to inherit multiple implementations of the same method from two different unrelated interfaces.
This seems to me to be contradictory. What am I missing? And BTW, I know the combinations of exactly what a class may or may not inherit when it comes to interfaces, interfaces extending interfaces, default methods, static methods etc, but I am concerned that this verbiage is quite ambiguous and at the end of the day I want to get a question on this correct with no room for doubt in my mind.Multiple inheritance of implementation is the ability to inherit method definitions from multiple classes. Java does not allow a class to extend from multiple classes but does allow a class to implement multiple interfaces. Prior to Java 8, interfaces were not allowed to contain any method implementation but with Java 8, interfaces can have method implementations in the form of "default" methods. This effectively allows a class inherit implementations from multiple sources. In other words, default methods introduce one form of multiple inheritance of implementation.
-
- Site Admin
- Posts: 10061
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1479 :
They are not contradictory at all. The first statement is talking about inheriting a method with the same signature from multiple super types and the other one is talking about inheriting method (not necessarily of methods with the same signatures) from multiple super types. Please go through the posts above and the link posted above.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 58 guests