File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Which overloaded method will be called if i am passing null as argument? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Which overloaded method will be called if i am passing null as argument?" Watch "Which overloaded method will be called if i am passing null as argument?" New topic
Author

Which overloaded method will be called if i am passing null as argument?

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Why the out put of below code is "String Version"


I was expecting that it should print "Object Verion"
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
When you make a call on overloaded methods the most specific one is called and definitely String is more specific than Object.
If you add following to your code you will get ambiguity as compiler have problem finding the specific one.


SCJP 1.6 96%
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Object class should be more specific not String class as Object is associated to all classes (As super class of all the classes).

Can you please clarify it a bit more?
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
A subclass is always more specific than its Super class. Object is more generalised class which every class extends to become a more specific one.
Can a object class do evrything what a String or any of its subclasses specifically do???
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Oh, Thank you so much for clearing the doubt
manishsharma sharma
Greenhorn

Joined: Jun 17, 2005
Posts: 24

I think this question is from Abhilash's quiz , which is quite useful for SCJP , I have did that quiz while preparing for my SCJP.

checkout for some more question

http://www.angelfire.com/or/abhilash/



Thanks
Manish
http://javatechtips.blogspot.com


Thanks, Manish
SCJP-100, SCMAD-91, SCWCD-89, http://javatechtips.blogspot.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which overloaded method will be called if i am passing null as argument?