What is the output of the following application?
package mypkg; // w w w . ja v a 2 s. c om interface Printable { void print() throws Exception; } public class Main implements Printable { public void print() { try { throws new RuntimeException("Circuit Break!"); } finally { System.out.print("Flipped!"); } } public static void main(String... electricity) throws Throwable { final Printable bulb = new Main(); bulb.print(); } }
print()
is an invalid method override. D.
The question is designed to see how closely you pay attention to throw and throws!
The try block uses the incorrect keyword, throws, to create an exception.
The code does not compile, and Option D is correct.
If throws was changed to throw, then the code would compile without issue, and Option B would be correct.