nerdexam
Oracle

1Z0-809 · Question #167

Given the code fragment: public static void main(String[] args) { ArrayList myList = new ArrayList(); String[] myArray = new String[5]; try { while (true) { myList.add("My String"); } } catch…

The correct answer is E. A runtime error is thrown in the thread "main". You've hit your session limit · resets 10:20pm (America/New_York)

Question

Given the code fragment: public static void main(String[] args) { ArrayList myList = new ArrayList(); String[] myArray = new String[5]; try { while (true) { myList.add("My String"); } } catch (RuntimeException re) { System.out.println("Caught a RuntimeException"); } catch (Exception ex) { System.out.println("Caught an Exception"); } System.out.println("Ready to use"); } What is the result?

Options

  • AThe code fails to compile because a throws keyword is required.
  • BExecution terminates in the second catch statement, and Caught an Exception is printed to the console.
  • CExecution terminates in the first catch statement, and Caught a RuntimeException is printed to the console.
  • DExecution completes normally, and Ready to use is printed to the console.
  • EA runtime error is thrown in the thread "main"

How the community answered

(19 responses)
  • A
    5% (1)
  • C
    11% (2)
  • D
    5% (1)
  • E
    79% (15)

Explanation

You've hit your session limit · resets 10:20pm (America/New_York)

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice