Sollicitatievraag bij MakeMyTrip

void sort(String s){ } void sort(Integer I){ } void sort(Object o){ } calling : sort(null) which function will be called?

Antwoorden op sollicitatievragen

Anoniem

12 jul 2016

Void Sort(String s) will be called , the reason is in java at run time method overloading goes with the most specific case and as we know null is an instance of string having length as 0.

1

Anoniem

27 okt 2018

It will show compiler error as it will be confused to go with Integer or String. But if have only Integer, or String or Object or String and Object both or Integer and Object both, it will compile successfully and will go to Integer or String method resp.

Anoniem

20 aug 2016

It'll fail with compile error. Its an ambiguous method call. because, both sort(String) and sort(Integer) will match 'null'. FYI, null is NOT an instance of String.