Method Overloading Tasks
Method Overloading Tricky Questions : class Test { void show(int a) { } void show(long a) { } public static void main(String[] args) { Test t = new Test(); t.show(10); } } ANSWER: show(int a) 10 is...

Source: DEV Community
Method Overloading Tricky Questions : class Test { void show(int a) { } void show(long a) { } public static void main(String[] args) { Test t = new Test(); t.show(10); } } ANSWER: show(int a) 10 is int → exact match is preferred over widening (int → long) class Test { void show(Integer a) { } void show(int a) { } public static void main(String[] args) { Test t = new Test(); t.show(10); } } ANSWER: show(int a) Exact primitive match is preferred over autoboxing (int → Integer) class Test { void show(int a, float b) { } void show(float a, int b) { } public static void main(String[] args) { Test t = new Test(); t.show(10, 10); } } ANSWER: Compile-time error (Ambiguous) Both require one widening conversion → compiler confused class Test { void show(int... a) { } void show(int a) { } public static void main(String[] args) { Test t = new Test(); t.show(10); } } ANSWER: show(int a) Normal method > varargs class Test { void show(int a) { } void show(int... a) { } public static void main(Stri