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
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)- A68% (17)
- C12% (3)
- D20% (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
Community Discussion
No community discussion yet for this question.