| Author |
q on wrapper classes
|
JayaSiji Gopal
Ranch Hand
Joined: Sep 27, 2004
Posts: 303
|
|
What is the output of trying to compile and run the following code? (Select one correct answer) -------------------------------------------------------------------------------- public class Test041 { static double d; static float f; public static void main(String args[]) { compare(Long.MAX_VALUE, Long.MAX_VALUE ); compare(Integer.MAX_VALUE, Integer.MAX_VALUE ); compare(Character.MAX_VALUE, Character.MAX_VALUE); compare(Short.MAX_VALUE, Short.MAX_VALUE ); compare(Byte.MAX_VALUE, Byte.MAX_VALUE ); } static void compare(double d, float f) { if (f == d) System.out.print(" equal" ); else System.out.print(" unequal"); } } -------------------------------------------------------------------------------- A: unequal equal equal equal equal B: equal unequal equal equal equal C: equal equal unequal equal equal D: equal equal equal unequal equal E: equal equal equal equal unequal I could not answer this q, can someone plz explain
|
SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
|
 |
sanjeevmehra mehra
Ranch Hand
Joined: Aug 21, 2004
Posts: 75
|
|
What is the output of trying to compile and run the following code? (Select one correct answer)
A: unequal equal equal equal equal B: equal unequal equal equal equal C: equal equal unequal equal equal D: equal equal equal unequal equal E: equal equal equal equal unequal I could not answer this q, can someone plz explain
Jayashree, pls. use CODE tag.
|
thanks & regards,<br />Sanjeev.
|
 |
sanjeevmehra mehra
Ranch Hand
Joined: Aug 21, 2004
Posts: 75
|
|
A. is ans. Long is 64 bit. float is 32 bit and value would be truncated & (changed automatically) so that would result unequal. rest of data type used are "less or equal" to 32 bit, value would be same for float(32 bits) & double (64 bits).
|
 |
Federico Zuppa
Greenhorn
Joined: Nov 23, 2004
Posts: 7
|
|
Something weird: I executed and printed the numbers in the method (see below) and for the Long numbers, it resulted in "equal" (though I see they are different). The Integers results in unequal (I read that "widening conversion of an int or long to a float may result in loss of precision however the new float value will be the correctly rounded" (http://www.janeg.ca/scjp/oper/conversions.html) so this should be allright). So correct option is B ? 9.223372036854776E18 9.223372E18 equal 2.147483647E9 2.14748365E9 unequal
|
 |
 |
|
|
subject: q on wrapper classes
|
|
|