Following Q is in javacertificate.com
Given the fragment of code is compiled to permit the use of the assert statement but disabled at runtime. What is the output if showFact is called with the following parameter value: "Scott"?
5. public static void showFact(
String explorer) {
6. if (explorer.equals("DaGama")) {
7. System.out.println("DaGama discovered a route to the East");
8. } else if (explorer.equals("Cook")) {
9. System.out.println("Cook reached Batavia,
Java in October 1770");
10. } else if (explorer.equals("Armstrong")) {
11. System.out.println("Armstrong was the first person on the moon");
12. } else if (explorer.equals("Drake")) {
13. System.out.println("Drake was involved in the slave trade");
14. } else {
15. assert false : explorer;
16. }
17. }
Options given are
1 An assertion error is thrown with the value Scott.
2 Cook reached Batavia, Java in October 1770 is displayed in the console.
3 Nothing is displayed in the console.
4 Scott is displayed in the console.
5 A null pointer exception is thrown
Answer given is 3. Can u tell me why is it so ?? why not 1 ?
Thanks in Advance,