nerdexam
Oracle

1Z0-803 · Question #69

Which two are possible outputs? public class Two { public static void main(String[] args) { try { doStuff(); system.out.println("1"); } catch { system.out.println("2"); }} public static void do Stuff(

The correct answer is A. 2 B. 4. A: Output is 2 if Math.random() is greater than 0.5. B: If Math.random() returns a value lessequalto0.5, the code won’t throw an exception, it will continue with the doMore() method which will println “4” after which the program will continue with the doStuff() method and will pr

Handling Exceptions

Question

Which two are possible outputs? public class Two { public static void main(String[] args) { try { doStuff(); system.out.println("1"); } catch { system.out.println("2"); }} public static void do Stuff() { if (Math.random() > 0.5) throw new RunTimeException(); doMoreStuff(); System.out.println("3 "); } public static void doMoreStuff() { System.out.println("4"); } }

Options

  • A2
  • B4
  • C1
  • D1

How the community answered

(25 responses)
  • A
    68% (17)
  • C
    12% (3)
  • D
    20% (5)

Explanation

A: Output is 2 if Math.random() is greater than 0.5. B: If Math.random() returns a value lessequalto0.5, the code won’t throw an exception, it will continue with the doMore() method which will println “4” after which the program will continue with the doStuff() method and will println “3”, after that we will be back in main() and the program will

Topics

#try-catch#RuntimeException#exception flow#conditional execution

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice