Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading and type conversion

 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • 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??
 
Vijay Gade
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The one with char.
 
achayya matta
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • 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: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks vijay and ashok
 
Ost. Ken
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi hope this will help



the result is "int"
[ November 23, 2005: Message edited by: Ost. Ken ]
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • 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
  • 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 ^^
 
AbhiRam Kalyan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
what "The Most Specific Method Is Chosen" in the sense.
any body please explain little bit more
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic