• Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic Question in overloading  RSS feed

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The answer for this question is "String Version" Please tell me why?
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through this at once...
 
John M Morrison
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! This is an important question and the answer is excellent.

JMM
 
Keith R Wegner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer for this question is "String Version" Please tell me why?


Hi - Java will look for the "most specific" method when determining which overloaded method it will call when running code.

When looking here, we have Object argument and a String argument in these methods' signatures.

Since String extends Object (as do all classes), we conclude the overloaded method containing String in the signature will be used in this code.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Art Vandelay, welcome to JavaRanch
 
Keith R Wegner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Art Vandelay, welcome to JavaRanch


Thank you. I'll be lurking around the JDBC, Java in General and SCJP boards for the time being.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!