This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Is Float more Specific than Double

kay lin
Ranch Hand
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
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 ]

kay lin
Ranch Hand
Posts: 132
I was looking at the answers at one of the pracitce questions
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
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++

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?