Welcome Guest | Sign in | Register
Exceptions - Discussion Page For Q.2608 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Exceptions > Questions and Answers

Q: class A{
static void test() throws RuntimeException {
try {
System.out.print("test ");
throw new RuntimeException();
}catch (Exception ex) {
 System.out.print("exception "); 
}
}
public static void main(String[] args) {
try { test(); }
catch (RuntimeException ex) { System.out.print("runtime "); }
System.out.print("end ");
}
What is the result?
A. test end B. Compilation fails.
C. test runtime end D. test exception end
E. A throwable is thrown by main at runtime.

Answer and Explanation

Answer:test exception end

Explanation:
From main ( ) method it will go to test ( ) method. Test ( ) method is throwing an exception and it has been handled here only. And when it comes back to main ( ) method it will not execute catch block. It will just execute last line that is System.out.println.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.