aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloaded DataTypes 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 "Overloaded DataTypes" Watch "Overloaded DataTypes" New topic
Author

Overloaded DataTypes

Saumya Srivastava
Ranch Hand

Joined: Mar 19, 2007
Posts: 45
Hi,

I was going through this question. And came across some doubts. If somebody can tell me that if there are multiple overloaded functions with different Datatypes then what is the trick to identify that which datatype will be selected? and if it has same datatype of primitive as well as wrapper then which one the compiler will choose to execute it?
The below code is from Certpal. I have modified it a bit.



Thanks in advance,
Saumya


OCPJP 6.0
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

1. You should remember there is no implicit downcasting in a method call, so if you have a code like this, it will not compile


2. between primitive and wrapper, primitive is chosen. This applies if the primitive is of the same type as the wrapper and if its of a different type (the latter case is called widening over boxing)...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Saumya Srivastava
Ranch Hand

Joined: Mar 19, 2007
Posts: 45
Ankit Garg wrote:1. You should remember there is no implicit downcasting in a method call, so if you have a code like this, it will not compile


Hi Ankit,

Thanks for your response. I got your second point but not the 1st point. What do you mean by saying implicit downcasting. Also, the line of code you highlighted is running.

Thanks,
Saumya
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Well the code that I gave should give an error that int cannot be automatically converted to short (you had me doubt my knowledge for a moment). You need to type cast the value 10 in the call to method to short for the code to compile...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloaded DataTypes