Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please tell me output flow for this program

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,


So when we call setName(null) the overloaded String method will get called .so please tell me the flow how the null is assigned to String here any how Object can take place of this part right...?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When there are multiple possibilities, Java will choose the most specific method. Since String is a subclass of Object, String is more specific, so the String version will be called. The version without any arguments isn't applicable when you call the method with one argument, even when the argument is null.

15.12.2.5 Choosing the Most Specific Method in the Java Language Specification explains all the details.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic