One of the answers is to remove 7. My question is what if there is an error caught, or no error, return f; will be called two times because finaaly{} has to be called. I have though return is like exit(0), but it appears not. How come the compiler permit two return calls in the same methods?
Could someone plz explain it for me? Thanks
Question ID :957639266007
What can be done to get the following code compile and run?
public float parseFloat(
String s )
{
float f = 0.0f; // 1
try
{
f = Float.valueOf( s ).floatValue(); // 2
return f ; // 3
}
catch(NumberFormatException nfe)
{
f = Float.NaN ; // 4
return f; // 5
}
finally {
return f; // 6
}
return f ; // 7
}