Oracle
1Z0-851 · Question #224
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…
The correct answer is B. Compilation fails. See the full explanation below for the reasoning.
Question
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?
Options
- A0.0
- BCompilation fails.
- CA ParseException is thrown by the parse method at runtime.
- DA NumberFormatException is thrown by the parse method at runtime.
How the community answered
(40 responses)- A5% (2)
- B78% (31)
- C15% (6)
- D3% (1)
Community Discussion
No community discussion yet for this question.