aspose file tools*
The moose likes Beginning Java and the fly likes Please tell me output flow for this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please tell me output flow for this program" Watch "Please tell me output flow for this program" New topic
Author

Please tell me output flow for this program

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
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...?


Creativity is nothing but Breaking Rules
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Thanks sir,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please tell me output flow for this program