Home » Oracle » 1z0-803 » 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");
}
}
Which two are possible outputs?
A. 2
B. 431
C. 1
D. 12
Correct Answer: AB
Explanation/Reference:
Explanation:
A: Output is 2 if Math.random() is greater than 0.5.
B: If Math.random() returns a value less equal to 0.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 print "1".
Download Printable PDF. VALID exam to help you PASS.
|
|