1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 Exam - Question 34


Given:

What is the result?

Show Answer
Correct Answer: AB

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

4 comments
Sign in to comment
TojoseOption: B
Jan 11, 2024

the right answer is B. D A D

james2033Option: B
Feb 22, 2024

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

xplorerpjOption: B
Jun 25, 2024

B is correct answer

manjulataOption: B
Jul 9, 2024

correct answer is DAD