File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 14074
    
  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,
 
Consider Paul's rocket mass heater.
 
subject: Please tell me output flow for this program
 
Similar Threads
When to use try/catch and throw ?
what is the out put of this program ? why ?
Question about ObjectOutputStream close() method
Overriding equals and hashcode for an Object.
Employee with same values is being added two times in HashSet