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

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
Pie
Posts: 15436
41
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