Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 34

Given:

What is the result?

    Correct Answer: B

    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'.

Discussion
TojoseOption: B

the right answer is B. D A D

james2033Option: B

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

manjulataOption: B

correct answer is DAD

xplorerpjOption: B

B is correct answer