hi class abc{ public void amethod(Object o){ System.out.println("Object version"); } public void amethod(String str){ System.out.println("String version"); }
public static void main(String[] args){ abc ob=new abc(); ob.amethod(null); } }//abc after compiling i am getting ans as String version can some one explain me why?
Rob Acraman
Ranch Hand
Joined: Dec 03, 2000
Posts: 89
posted
0
Whenever there is an ambiguous function call, Java will always attempt to call the most specific class available. In this case, since null matches both Object and String, and since String inherits from Object, String is the most specific. Note that, if you had "sibling" methods - eg. you added "amethod(Integer x)", then there would be no clear-cut 'most specific' method so you would get an error.
Rishi Yagnik
Ranch Hand
Joined: Jan 04, 2001
Posts: 84
posted
0
Thanks Rob i got u infact i have got the same concept in my mind but thanks for Explanation.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.