| 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/
|
 |
 |
|
|
subject: Which overloaded method will be called if i am passing null as argument?
|
|
|