venerdì 29 marzo 2013

Q87

Given:
public class Main {
       public static void main(String[] args) throws Exception {
             doSomething();
       }
       private static void doSomething() throws Exception {
             System.out.println("Before if clause");
             if (Math.random() > 0.5) {
                    throw new Exception();
             }
             System.out.println("After if clause");
       }
}

Which two are possible outputs?
A.
Before if clause
Exception in thread “main” java.lang.Exception
AtMain.doSomething (Main.java:8) At Main.main (Main.java:3)
B.
Before if clause
Exceptionin thread “main” java.lang.Exception
At Main.doSomething (Main.java:8) At Main.main (Main.java:3) After if clause
C.
Exception in thread “main” java.lang.Exception
At Main.doSomething (Main.java:8) At Main.main (Main.java:3)
D.
Before if clause
After if clause

2 commenti: