public class OverloadingTest extends Format{ public int add(String s1){ System.out.println("With String"); return 1; } public int add(Object a){ System.out.println("With Object"); return 1; } public static void main(String[] args) { OverloadingTest overloadingTest = new OverloadingTest(); overloadingTest.add(null); } } Why is the output of the program With String ?
I have tried reading JLS for 6th Version, but I still could not find the answer.
The only reason I could guess is that the closest match in Inheritance hierarchy is chosen.
So in this case it would take String as Object is its super class.