What is the output of the following application?
package mypkg; /* w ww . java 2 s . co m*/ public class Main { public static String getFullName(String firstName, String lastName) { try { return firstName.toString() + " " + lastName.toString(); } finally { System.out.print("Finished!"); } catch (NullPointerException npe) { System.out.print("Problem?"); } return null; } public static void main(String[] things) { System.out.print(getFullName("A","B")); } }
D.
This code does not compile because the catch and finally blocks are in the wrong order, making Option D the correct answer.
If the order was flipped, the output would be Finished!A B, making Option B correct.