What is the result of the following code?
1: public interface Printable { 2: default void print() { System.out.println("Printing"); } 3: } // www. ja v a 2 s. co m 4: public interface Displayable { 5: public default void print() { System.out.println("Printing"); } 6: public abstract void run(); 7: } 8: public interface Drawing extends Printable, Displayable { 9: void sprint(); 10: }
D.
While Java supports multiple inheritance through interfaces, it does not support method overriding in interfaces, since it's not clear which parent method should be used.
In this example, Printable and Displayable both implement a default print()
method.
The definition of Drawing extends these two interfaces and therefore won't compile as two default methods with the same signature from parent classes are detected, therefore the answer is D.
None of the other lines of code cause problems, so the rest of the answers are not correct.