File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about null" Watch "about null" New topic

about null

wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
public class AQuestion
public void method(Object o)
System.out.println("Object Verion");
public void method(String s)
System.out.println("String Version");
public static void main(String args[])
AQuestion question = new AQuestion();
The code does not compile.
The code compiles cleanly and shows "Object Version".
The code compiles cleanly and shows "String Version"
The code throws an Exception at Runtime.
the ans is 3rd.
i thought if the code were written like 'questin.method("null")', the ans were 3rd, but .... i dont know why?
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
In method overloading compiler looks for the most specific method in selection.Here null can be easily passed to String version.
However it can pass to Object versions too but its not more specific than Strings version.
Count the flowers of ur garden,NOT the leafs which falls away!

Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining
I agree. Here's the link:
subject: about null
jQuery in Action, 3rd edition