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

Home > Java Programming > Exceptions > Questions and Answers

Q: Given:
public static void parse(String str) {
try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally {
System.out.println(f);
}
}
public static void main(String[] args) {
parse("invalid");
}

What is the result?
A. 0.0 B. Compilation fails.
C. A ParseException is thrown by the parse method at runtime. D. A NumberFormatException is thrown by the parse method at runtime.

Answer and Explanation

Answer:Compilation fails.

Explanation:
Compilation fails because all the code is not there in any of the class. One more reason is inside a try they have declared a variable f and they are trying to access from finally block, it will throw compile time error.

Comment on this Question

Name:

Loading...




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