Oracle
1Z0-805 · Question #24
Given the code fragment: public class TestString { public static void main(String[] args) { String str=null; switch(str) { case "": System.out.println("blank"); break; case "null"…
Sign in or unlock 1Z0-805 to reveal the answer and full explanation for question #24. The question stem and answer options stay visible for context.
Java Class Design
Question
Given the code fragment:
public class TestString { public static void main(String[] args) { String str=null; switch(str) { case "":
System.out.println("blank"); break; case "null":
System.out.println("NULL"); break; default:
System.out.println("invalid"); break; } } } What is the result?
Options
- ACompilation fails
- BBlank
- CNULL
- DAn exception is thrown at runtime
- EInvalid
Unlock 1Z0-805 to see the answer
You've previewed enough free 1Z0-805 questions. Unlock 1Z0-805 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.
Topics
#switch on null#NullPointerException#String switch#null handling