Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the out put of below code is "String Version"


I was expecting that it should print "Object Verion"
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, Thank you so much for clearing the doubt
 
manishsharma sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic