| Author |
Why this Output?
|
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Hi Ranchers, Consider the following code, Why it prints 3 instead of 2? Regards, Jothi Shankar Kumar. S
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
Originally posted by Jothi Shankar Kumar Sankararaj: Hi Ranchers, Consider the following code, Why it prints 3 instead of 2? Regards, Jothi Shankar Kumar. S
There is only one method which matches the call.
|
 |
Anand Loni
Ranch Hand
Joined: Jan 20, 2006
Posts: 150
|
|
Hi, 2 is not printed because third parameter is integer and it can not converted to byte without explicit cast. Regards, Anand
|
~ Anand,
SCJP 1.5
SCWCD 1.5
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Hi Anand, your quote:
Hi, 2 is not printed because third parameter is integer and it can not converted to byte without explicit cast. Regards, Anand
The third parameter's value is 3 which very well fits into a byte??So why not it take the 2nd method and print 2 at the output? Regards, Jothi Shankar Kumar. S
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
Method invocation conversion does not include narrowing primitive conversions. 3 is an int. It cannot be converted to a byte when it is sent as a parameter to a method that expects a byte.
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Hi Keith, So when it comes to method invocation, any number of type 3.0, 55.0 is treated as double and numbers like 45, 888888 are treated as int. am I right? Regards, Jothi Shankar Kumar. S
|
 |
Sharmila Rishi
Greenhorn
Joined: Oct 11, 2006
Posts: 20
|
|
So when it comes to method invocation, any number of type 3.0, 55.0 is treated as double and numbers like 45, 888888 are treated as int. am I right?
Yes, you are right. Any floating point point value without a 'f' is implicitly a double and any numeric value is implicitly an int. -Sharmila Rishi.
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Hi Sharmila, Thanks for the comments. Regards, Jothi Shankar Kumar. S
|
 |
 |
|
|
subject: Why this Output?
|
|
|