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 overloading question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overloading question" Watch "overloading question" New topic
Author

overloading question

Paula Jiang
Greenhorn

Joined: Feb 15, 2003
Posts: 15
What will happen when you compile and run the following code?


SCJP2 1.4 (96%) SCWCD(96%)
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
compiler will generate an error because the call

in the main() method is ambiguous.It means the complier don't know what method to call when it bounds the parameter "null"!
the

or the

?
I just compiled it


a beginner in java
Sridhar Srikanthan
Ranch Hand

Joined: Jan 08, 2003
Posts: 366
compiler will generate an error because the call

Compiler will not generate any error. Infact the program also runs and gives the result of m2.
This is because the compiler will map null to the "most specific object" that null can be cast into which is String.
The rule is String is-a Object but Object is-not-a String .
so the null is cast into a string.
I remember reading it somewhere in JLS via one of Dan's mock exams. Search the post and you will find the solution in one of the posts
Thanks
Sri
[ February 15, 2003: Message edited by: Sri Sri ]
Paula Jiang
Greenhorn

Joined: Feb 15, 2003
Posts: 15
it compiles and runs fine just like Sri Sri said, but I want to know why. Thanks Sri sri
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Related discussions:
null arg in overloaded method
null argument to a method - what is being passed??


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overloading question
 
Similar Threads
Thread doubt about wait() method
static
Overloading or Overriding ?
can anyone explain me the output..??
question about polymorphism