nerdexam
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)
  • A
    5% (2)
  • B
    78% (31)
  • C
    15% (6)
  • D
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice