Consider the following method -
public float parseFloat ( String s ){ float f = 0.0f; try{//from w w w . j av a2s . c o m f = Float.valueOf ( s ).floatValue (); return f ; } catch (NumberFormatException nfe){ f = Float.NaN ; return f; } finally{ f = 10.0f; return f; } }
What will it return if the method is called with the input "0.0" ?
Select 1 option
Correct Option is : B
finally block will always execute (except when there is a System.exit()
in try or catch).
And inside the finally block, it is setting f to 10.0.
So no matter what the input is, this method will always return 10.0.