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
davidkkkk
Posts: 6
Joined: Fri Mar 20, 2015 8:42 am
Contact:

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

Post by davidkkkk »

You cannot have a class that implements two interfaces where both the interfaces contain a default method with the same signature.
In fact you can rase this ambiguity by overriding the method with the same signature in the class. This compile and print "in CI.m1".

Code: Select all

class MyTest {
        public static final void main(String[] args) {
                new CI().m1();
        }
}

interface I1 {
        public default void m1() {
                System.out.println("in I1.m1");
        }
}

interface I2 {
        public default void m1() {
                System.out.println("in I2.m1");
        }
}
class CI implements I1, I2 {
        public void m1() {
                System.out.println("in CI.m1");
        }
}
Of course this answer remains wrong because you can't have multiple implementation.

admin
Site Admin
Posts: 10389
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 has been updated to make it clear.
thank you for your feedback!

Patrick75
Posts: 4
Joined: Sun Apr 12, 2015 10:34 am
Contact:

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

Post by Patrick75 »

In the explanation of the question in the ETS viewer the 'default' keyword is used in the class declaration, is this a copy and paste error or is it allowed to use it like this in a class as well?

Code: Select all

class C2 implements I1, I2 {
        public default void m1() {
                System.out.println("in C2.m1");
        }
}

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

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

Post by admin »

No, that's a copy paste mistake. Fixed.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests