What is the result of compiling and executing the following application?
package mypkg; //from w w w . ja va 2s . c om public class Main { public static void think() throws Exception { // k1 try { throw new Exception(); } } public static void main(String... ideas) throws Exception { think(); } }
D.
A try block must include either a catch or finally block, or both.
The think()
method declares a try block but neither additional block.
The code does not compile, and Option D is the correct answer.
The rest of the lines compile without issue, including k1.