Java OCA OCP Practice Question 625

Question

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")); 
   } 
} 
  • A. A B
  • B. Finished!A B
  • C. Problem?Finished!null
  • D. None of the above


D.

Note

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.




PreviousNext

Related