Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Java Question
Shyam Ramath
Greenhorn
Posts: 21
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class Stringtest { public static void main(String[] args) { // TODO Auto-generated method stub Stringtest question = new Stringtest(); question.method(null); question.method((String)null); question.method((Object)null); } public void method(Object o) {System.out.println("Object Verion"); } public void method(String s) {System.out.println("String Version"); } }
Out of this program is
----------------------------
String
Version
String Version
Object Verion
Could anyone explain why String Objects are invoked when 'null' is passed as parameter ?
Thanks
-Shyam
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The rule is that the most specific applicable overload applies. "null" could be either String or Object, but String is more specific since it's a subclass of Object, and so String is chosen.
[Jess in Action]
[AskingGoodQuestions]
Shyam Ramath
Greenhorn
Posts: 21
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ok . That means the it narrows down from the child class . Thanks
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
null arg in overloaded method
Regarding String
Overloading question...
String explain output
Which overloaded method will be called if i am passing null as argument?
More...