• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why this Output?

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Consider the following code,



Why it prints 3 instead of 2?

Regards,
Jothi Shankar Kumar. S
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

2 is not printed because third parameter is integer and it can not converted to byte without explicit cast.

Regards,
Anand
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sharmila,

Thanks for the comments.

Regards,
Jothi Shankar Kumar. S
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic