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(); question.method(null); } } Answers 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
posted
0
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. Bye. Viki. ------------------ Count the flowers of ur garden,NOT the leafs which falls away!