About Question enthuware.ocajp.i.v8.2.1479 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
bortnikov_sa@mail.ru
Posts: 8
Joined: Wed Oct 25, 2017 2:53 am
Contact:

About Question enthuware.ocajp.i.v8.2.1479 :

Post by bortnikov_sa@mail.ru »

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{
}

admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1479 :

Post by admin »

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.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1479 :

Post by __JJ__ »

In the answer to another question (in another test) you stated:
However, Java 8 still does not allow a class to inherit multiple implementations of the same method from two different unrelated interfaces.
Now in this question you are saying that one of the correct answers is:
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.
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.

admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1479 :

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests