• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

What would be the result and why ?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What would be the result and why ?

class D {
static String m(float i) {return "float";}
static String m(double i) {return "double";}

public static void main (String[] args) {
int a1 = 1;
long b1 = 2;
System.out.print(m(a1)+","+ m(b1));

}}
Thanks
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What would be the result



Recommend you to install the JDK on your machine.

and why



A float can comfortably accomodate a long (and of course an int) within its range.

From the JLS:

The following 19 specific conversions on primitive types are called the widening primitive conversions:
� byte to short, int, long, float, or double
� short to int, long, float, or double
� char to int, long, float, or double
int to long, float, or double
long to float or double
� float to double


[ December 12, 2006: Message edited by: Aniket Patil ]
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
float, float will be the O/P.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And where did the question come from? Please always quote the source of the mock exam. If not then we will lock the topic until you do.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
m(float) is more specific that m(double) for calls using int and long.
 
manishsharma sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys
 
reply
    Bookmark Topic Watch Topic
  • New Topic