This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Similar Threads
Passing null to Obj,String args methods
about overloading
mock exam question
Doubt in overloaded method related question
question in javaquiz