Given:
What is the result?
Given:
What is the result?
The method calls to t.sum(10, 15.25), t.sum(10, 24), and t.sum(10.25, 10.25) invoke the overloaded methods based on parameter types matching the most specific signature. The first call t.sum(10, 15.25) matches the method public void sum(int a, float b), so 'B' is printed. The second call t.sum(10, 24) matches the method public void sum(int a, int b), so 'A' is printed. The third call t.sum(10.25, 10.25) matches the method public void sum(double... a) due to the varargs with doubles, so 'D' is printed. Therefore, the result is 'D A D'.
the right answer is B. D A D
package q34; public class Test { public void sum(int a, int b) { System.out.print(" A"); } public void sum(int a, float b) { System.out.print(" B"); } public void sum(float a, float b) { System.out.print(" C"); } public void sum(double... a) { System.out.print(" D"); } public static void main(String[] args) { Test t = new Test(); t.sum(10, 15.25); t.sum(10, 24); t.sum(10.25, 10.25); } } // Result: // D A D
correct answer is DAD
B is correct answer