Multiple choice technology programming languages

Given: 11. public enum Title { 12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”); 13. private final String title; 14. private Title(String t) { title = t; } 15. public String format(String last, String first) { 16. return title + “ “ + first + “ “ + last; 17. } 18. } 19. public static void main(String[] args) { 20. System.out.println(Title.MR.format(”Doe”, “John”)); 21. } What is the result?

  1. Mr. John Doe

  2. An exception is thrown at runtime

  3. Compilation fails because of an error in line 12

  4. Compilation fails because of an error in line 15

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The enum constant MR has title="Mr.". When format("Doe", "John") is called, it concatenates title + " " + first + " " + last, producing "Mr. John Doe". Note that last name is passed as the first parameter and first name as the second.