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

Home > Java Programming > Exceptions > Questions and Answers

Q: 1. What will be the output of the program?
public class RTExcept {
public static void throwit (){
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args){
try{
System.out.print("hello ");
throwit();
}catch (Exception re ) {
System.out.print("caught ");
}finally{
System.out.print("finally ");
}
System.out.println("after ");
}
}
A. hello throwit caught B. Compilation fails
C. hello throwit RuntimeException caught after D. hello throwit caught finally after

Answer and Explanation

Answer:hello throwit caught finally after

Explanation:
The main ( ) method properly catches and handles the RuntimeException in the catch block, finally runs (as it always does), and then the code returns to normal.
A, B and C are incorrect based on the program logic described above. Remember that properly handled exceptions do not cause the program to stop executing.

Comment on this Question

Name:

Loading...




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