nerdexam
Oracle

1Z0-851 · Question #105

Given: public static void main(String[] args) { try { args = null; args[0] = "test"; System.out.println(args[0]); } catch (Exception ex) { System.out.println("Exception"); } catch…

The correct answer is C. Compilation fails. See the full explanation below for the reasoning.

Question

Given: public static void main(String[] args) { try { args = null; args[0] = "test"; System.out.println(args[0]); } catch (Exception ex) { System.out.println("Exception"); } catch (NullPointerException npe) { System.out.println("NullPointerException"); } } What is the result?

Options

  • Atest
  • BException
  • CCompilation fails.
  • DNullPointerException

How the community answered

(19 responses)
  • A
    5% (1)
  • B
    11% (2)
  • C
    74% (14)
  • D
    11% (2)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice