Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is Float more Specific than Double

 
kay lin
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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++
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic