aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is Float more Specific than Double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is Float more Specific than Double" Watch "Is Float more Specific than Double" New topic
Author

Is Float more Specific than Double

kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
Hi :
I was doing one of the practice exams and come across conversion.

Just wondering, is float more specific than double?

i think float is 32 bits and double is 64
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
float and double are primitive types, not class instance types. So what do you mean by "more specific"?

If you mean Float and Double as wrapper classes then, the two classes are distinct subclasses of class Number.
[ November 17, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
I was looking at the answers at one of the pracitce questions
Answers
Take a look at answer No.2,
I was confused as to what he meant by float is more "specific" than double..
Franz Fountain
Ranch Hand

Joined: Nov 15, 2006
Posts: 58
Hi Kay,

You're right that float is 32 bits and double is 64 bits. So from a point of view of widening the least wide parameter that matches should be used. O can understand that int which is 32 bits would prefer float over double. What surprises me is that long which is 64 bits would fit in a float. In fact I started a new topic regarding this.

As far as which is more specific, the explanation doesn't actually say that a long is more specific than a double. It says the Method that uses a long is more specific than the Method that uses a double. I guess the word specific has a specific meaning when it comes to OOP with regards to classes. I don't know if it's really proper to say one Method is more specific than another. In a sense I suppose you could say a float IS-A double because any float will fit in a double, but that's stretching it I suppose. It's just using IS-A in terms of a subset which is part of the meaning in OOP but doesn't taken into account things like polymorphism.

Oh well, I guess different people have different ideas about what is OOP - just look at C++
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is Float more Specific than Double