• 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

Kathy's book - chapter 6 - question #7

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is a, b, and d. What types of implicit conversions are going on for b and d?
Thanks.
Mansi
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As not everyone has a copy of the book (including myself), you might find that you get more responses if you were to include the original question in your post.
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that in b 2.3 is truncated to an int value of 2, thus the version of Math.max is the one that takes 2 ints.
And in D the -2.8f is widened to a double, thus in this case the version of Math.max is the one that accepts 2 doubles.
 
Mansi Vyas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for not including the question. Here it is...
Which of the following are valid calls to Math.max? Choose all that apply.
A. Math.max(1,4)
B. Math.max(2.3, 5)
C. Math.max(1,3,5,7)
D. Math.max(-1.5, -2.8f)
In choice B, I think that the 5 is being implicity converted to a 5.0(double). In choice D, I think that -2.8f is being implicity promoted to a double. Both are invoking the following method signiture, double max(double a, double b).
Is this correct?
Thanks.
Mansi
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct...
The thing to remember here is this order:
byte
short
int
long
float
double
So, for example, in option D. we have a float and a double, so we know that float can be implicitly promoted to a double.
HTH
 
reply
    Bookmark Topic Watch Topic
  • New Topic