• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

What would be the result and why ?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
  • 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: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
float, float will be the O/P.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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: 2410
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks guys
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic