aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What would  be the result and why ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What would  be the result and why ?" Watch "What would  be the result and why ?" New topic
Author

What would be the result and why ?

manishsharma sharma
Greenhorn

Joined: Jun 17, 2005
Posts: 24
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


Thanks, Manish
SCJP-100, SCMAD-91, SCWCD-89, http://javatechtips.blogspot.com/
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
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 ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9622
    
    2

float, float will be the O/P.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
m(float) is more specific that m(double) for calls using int and long.
manishsharma sharma
Greenhorn

Joined: Jun 17, 2005
Posts: 24
thanks guys
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What would be the result and why ?