The following method is designed to convert an input string to a floating point number while detecting a bad format.  [I think factor must have been declared as float member variable or something]
Which of the following descriptions of the results of various inputs to the method are correct? (a)Input = �0.234� � Result: factor = 0.234, �Finally� is printed, true is returned. (b)Input = �0.234� � Result: factor = 0.234, �Finally� is printed, false is returned. (c)Input = null � Result: factor = NaN, �Finally� is printed, false is returned. (d)Input = null � Result: factor = unchanged, �Finally� is printed, NullPointerException is thrown.
frnds , option a is correct ..that is fine ...i cannot understand why opition is correct ...specifically factor = unchanged i didnt get
can anyone clarify it
sri [ October 13, 2005: Message edited by: Barry Gaunt ]
(d)Input = null � Result: factor = unchanged, �Finally� is printed, NullPointerException is thrown.
Its simple factor = Float.valueOf(s).floatValue(); In this statement the exception occurs while performing Float.valueOf(s) ie. before calculating .floatValue() and before assigning the calculated value to the variable factor. As soon as the exception occurs control jumps to the corresponding exception handler withoug assigning anything to factor. hence factor remain unchanged.
Hope it helps
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?