nerdexam
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)
  • A
    7% (2)
  • B
    10% (3)
  • C
    3% (1)
  • D
    76% (22)
  • E
    3% (1)

Explanation

Incorrect else syntax.

Topics

#Java syntax#if-else structure#compilation error#null check

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice