Thursday Java programming challenge, let's see who cracks it 😀. Method overloading using null. #799
-
public class OverloadTest { public static void test(String s) { public static void test(Integer i) { what will be the output? |
Beta Was this translation helpful? Give feedback.
Answered by
aysha-siddqua
Aug 7, 2025
Replies: 1 comment
-
The code actually won’t compile. When you call test(null), Java can’t decide between String and int, both are valid matches for null and neither is more specific than the other. So the compiler throws an ‘ambiguous method call’ error. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
im-ahmed-hasan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code actually won’t compile. When you call test(null), Java can’t decide between String and int, both are valid matches for null and neither is more specific than the other. So the compiler throws an ‘ambiguous method call’ error.