Page 1 of 1

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

Posted: Mon Mar 30, 2015 9:31 am
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.

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

Posted: Mon Mar 30, 2015 8:07 pm
by admin
You are right. The explanation has been updated to make it clear.
thank you for your feedback!

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

Posted: Tue May 05, 2015 7:42 am
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");
        }
}

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

Posted: Tue May 05, 2015 8:14 am
by admin
No, that's a copy paste mistake. Fixed.
thank you for your feedback!