• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Overloading and type conversion

 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The one with char.
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks vijay and ashok
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi hope this will help



the result is "int"
[ November 23, 2005: Message edited by: Ost. Ken ]
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ost. Ken
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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 ^^
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
what "The Most Specific Method Is Chosen" in the sense.
any body please explain little bit more
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic