aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question regarding passing null into method parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question regarding passing null into method parameter" Watch "Question regarding passing null into method parameter" New topic
Author

Question regarding passing null into method parameter

Dhruv Arya
Greenhorn

Joined: Mar 30, 2009
Posts: 26


How to know which gets invoked ?? I tried it out the string version does but how ? and also if we remove the string version the Integer Version gets invoked and removing that then the Object Version so how do we know which to choose?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I complied your code and it throws the error like "reference to method is ambiguous, both method method(String s) and method(Integer s)".

The rule is something like this:
The method which is nearest to the parameter is called first, means, the child class object is first checked, then its parent, and then its parent and so on..
e.g

If we comment out the "integer version", then it looks for parent class
e.g


HTH


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Dhruv Arya
Greenhorn

Joined: Mar 30, 2009
Posts: 26
Thanks alot I got what you were trying to say.. Thanks alot !
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You're welcome I saw this type of questions many time here. Just search this forum with tags like "method calling sequence", "which method get invoked". etc
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

Actually there is a important thing to remember. If you have overloaded methods with parameters in the same inheritance tree then the lowest level subclass will be invoked. If any other type is included then it will be ambiguous as both the types can accept the argument value.


[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Nitish Bangera wrote:If you have overloaded methods with parameters in the same inheritance tree then the lowest level subclass will be invoked.

I think, this is more technical version of what I want to say
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question regarding passing null into method parameter
 
Similar Threads
JQuest: String & StringBuffer
how to invoke the overload method when use null as argument?
which method to use?
Method Overloading
q from jiris.com