35. What is the result of the following code when you compile and run?
public class ThrowDemo {
static void demoMethod() {
try {
throw new NullPointerException("demo");
} catch(NullPointerException e) {
System.out.println("Caught inside demoMethod.");
throw e; // re-throw the exception
}
}
public static void main(String args[]) {
try {
demoMethod();
} catch(NullPointerException e) {
System.out.println("Recaught: " + e);
}
}
}
[a] Compilation error
[b] Runtime error
[c] Compile successfully, nothing is printed.
[d] Caught inside demoMethod. followed by Recaught: java.lang.NullPointerException: demo
Answer
[d] Caught inside demoMethod. followed by Recaught: java.lang.NullPointerException: demo |