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

Overloading problem

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
Hi, Can anybody explain the reason of ambiguity here.

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Hint: char can be automatically upcasted to float...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774


First thing i suppose that var-args are the last choice made by the compiler. In your case, if your see there is already a more specific method
present that is number 1 which takes a float. Now when you try to invoke the method calls from your main method, in your second call, as Ankit
told character is automatically up-casted to float then the compiler gets confused, which method to call as there is already a more specific method
present. Thats why it gives the ambiguity error. Hope this helps.


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
So you mean character can be automatically casted to int, float etc
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Jacob Sonia wrote:So you mean character can be automatically casted to int, float etc

Yes
 
 
subject: Overloading problem