GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overloading example from examlab 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 "overloading example from examlab" Watch "overloading example from examlab" New topic
Author

overloading example from examlab

S Ali
Ranch Hand

Joined: Aug 23, 2009
Posts: 129



My doubt is how come capture(s1+=20000) evaluate to short !! isn't 20000 considered an integer literal therefore producing the output as an int?


SCJP 6
S Ali
Ranch Hand

Joined: Aug 23, 2009
Posts: 129
ok then s1+=20000 is different from s1 = s1 + 20000
Dejan Miler
Ranch Hand

Joined: Nov 14, 2009
Posts: 56


First thing that is happens here is that JVM pass reference value s1 which is 6 to the method and when that method execution
is over then JVM add value of 20000 to the value of s1.

Dejan


SCJP 1.6 in progress ....
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
What about capture();?? why it prints "F"??
I dont know why it is considering as varargs i.e; Long... x in this program..

can anyone help me??
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
var...arg means zero or more argument.

In the above program the only function that can take zero argument is capture and hence the output F.

But if the function call has arguments then compiler will choose var...arg method as the last option to select from.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
Thanks Siva Masilamani
Francisco Montes
Ranch Hand

Joined: Sep 30, 2009
Posts: 30
Dejan,

I´m sorry but it does not work the way you mentioned. Try this:



This is the output:
Value received in capture method: 20006
Value after calling capture: 20006

So in fact, the expression is completely evaluated before passing its result into the method.

SCJP 1.6
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
compiler converts this


to this



and s+=20000; works differently then s=s+2000; as
for s+=2000; implicit conversion is done from int to short.
and for s=s+2000; we need to do explicit conversion.

SCJP 6
 
GeeCON Prague 2014
 
subject: overloading example from examlab