Java.lang Class

Q1: What will be the output of the program?
try 
{
    Float f1 = new Float('3.0');
    int x = f1.intValue();
    byte b = f1.byteValue();
    double d = f1.doubleValue();
    System.out.println(x + b + d);
}
catch (NumberFormatException e) /* Line 9 */
{
    System.out.println('bad number'); /* Line 11 */
}

A 9.0

B bad number

C Compilation fails on line 9.

D Compilation fails on line 11.

ANS:A - 9.0

The xxxValue() methods convert any numeric wrapper object's value to any primitive type. When narrowing is necessary, significant bits are dropped and the results are difficult to calculate.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.