File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading and type conversion 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 and type conversion" Watch "Overloading and type conversion" New topic

Overloading and type conversion

Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
I have a method CALL which passes a character as an argument, and the class defines two methods of same name one with argument of type character and another of type int. Which method will be called at runtime, the one with int or the one with character??

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Vijay Gade
Ranch Hand

Joined: Jul 04, 2005
Posts: 81
The one with char.
achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111
Ya Akhil,
in such cases "The Most Specific Method Is Chosen"
Read JLS2.0 for more details.Hope it helps u!
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
thanks vijay and ashok
Ost. Ken

Joined: Aug 24, 2005
Posts: 4
hi hope this will help

the result is "int"
[ November 23, 2005: Message edited by: Ost. Ken ]
Brian Cole
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
I thought your example was a hoot, Ost. Ken,
but I fear that many here will not see your
slight-of-hand and misunderstand things.

We all agree that if you write the second
test() method to take a parameter of type
char instead of Character that the result
will not be "int", right?
[ November 23, 2005: Message edited by: Brian Cole ]

bitguru blog
Ost. Ken

Joined: Aug 24, 2005
Posts: 4
if Character change to char result will not be "int".

sry about my bad sample ....
i think the correct answers was already replied by vijay and ashok

My purpose is to show Autoboxing/Unboxing will not use in this case(but i didn't tell that my sample is for 5.0 ...very very sry about that).

thank you for ur comment Brian ^^
AbhiRam Kalyan

Joined: Oct 31, 2005
Posts: 25
what "The Most Specific Method Is Chosen" in the sense.
any body please explain little bit more

I agree. Here's the link:
subject: Overloading and type conversion
Similar Threads
Wrapper confusion
Overloading and argument type conversion
String indexOf(int)
Please , what is the answer to this question
indexOf(int ch)