What is the result of: new Document().print();
Exhibit
Refer to the exhibit.
interface Printable {
default void print() { System.out.println("Printable"); }
}
interface Showable {
default void print() { System.out.println("Showable"); }
}
class Document implements Printable, Showable {
// no override
}Trap 1: Printable
Incorrect. The code never runs to produce a result; it fails at compile time.
Trap 2: Runtime exception
Incorrect. A runtime exception is not thrown because the program never compiles.
Trap 3: Showable
Incorrect. The code does not compile, so `Showable` is not printed.
- A
Printable
Why wrong: Incorrect. The code never runs to produce a result; it fails at compile time.
- B
Runtime exception
Why wrong: Incorrect. A runtime exception is not thrown because the program never compiles.
- C
Compilation fails
Correct. The ambiguity between the two default `print()` methods causes a compilation failure.
- D
Showable
Why wrong: Incorrect. The code does not compile, so `Showable` is not printed.