• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

q on wrapper classes

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
sanjeevmehra mehra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic