Oracle
1Z0-851 · Question #45
Given: public static void main(String[] args) { String str = "null"; if (str == null) { System.out.println("null"); } else (str.length() == 0) { System.out.println("zero"); } else {…
The correct answer is D. Compilation fails. Incorrect else syntax.
Analyzing and Troubleshooting System Problems
Question
Given: public static void main(String[] args) { String str = "null"; if (str == null) { System.out.println("null"); } else (str.length() == 0) { System.out.println("zero"); } else { System.out.println("some"); } } What is the result?
Options
- Anull
- Bzero
- Csome
- DCompilation fails.
- EAn exception is thrown at runtime.
How the community answered
(29 responses)- A7% (2)
- B10% (3)
- C3% (1)
- D76% (22)
- E3% (1)
Explanation
Incorrect else syntax.
Topics
#Java syntax#if-else structure#compilation error#null check
Community Discussion
No community discussion yet for this question.