wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Ranch roundup game question 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 "Ranch roundup game question" Watch "Ranch roundup game question" New topic

Ranch roundup game question

Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Hi Friends,
I got this question:

But,I answered "No",as I read this in the JLS specification:

The also explained that it was done so as not to confuse regarding overloading.So,why the answer was "Yes",please explain this to me guys!!!

SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
You're not "narrowing" when you go from short to int. It would be narrowing when you go from int to short.

James Carman, President<br />Carman Consulting, Inc.
Karthikeyan Varadarajan
Ranch Hand

Joined: Jul 04, 2002
Posts: 98
You can send int while the funtion expects int. but the vice versa is true.

while coming to overloading ,

the compiler try to match the argument type and if it is not find a correct method , then try to widen the values and match (short to int or int to long).

public class OverLoadTest {

public static void main(String[] args) {

OverLoadTest test = new OverLoadTest();
short ding = 5;


/* public void checkOverLoad (int one)
System.out.println("CheckOverLoad for int called");

/* public void checkOverLoad (short two)
System.out.println("CheckOverLoad for Short called");

public void checkOverLoad (long three)
System.out.println("CheckOverLoad for Long called");


~With Smile<br />VK
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Thanks James and BlackFire,
So,that only happens for narrowing and not widening..got it!!!
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Thanks James and blackfire,
Nice Example. I got the point.
[ May 06, 2005: Message edited by: Raghu Shree ]

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi james

i didn't understand what the jls saying Method Invocation Conversions do not include implicit narrowing of integer constants as in Assignment conversions.

i learnt that in assignment coversion. we can assign int to short i.e narrowing on explicitly casting.
i.e Short s=(Short)5;

is the jls saying the above conversion is not allowed during the method invocation.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
It means that you can do this...

But, you can't do this...

Consider Paul's rocket mass heater.
subject: Ranch roundup game question
Similar Threads
implicit and explicit conversion
assignments and casting
Assignment question
Autoboxing AutoUnboxing problem
Boone's mockexam question