Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 171

Given:

What is the result?

A.

B.

C.

D.

    Correct Answer:

    The given code demonstrates method overloading in Java, where three different versions of the 'doSum' method are defined to accept arguments of type Integer, double, and float respectively. The main method calls 'doSum' with two sets of arguments: (10, 20) and (10.0, 20.0). When the method is called with the integers 10 and 20, the version of 'doSum' that accepts Integer arguments is invoked, resulting in the output 'Integer sum is 30'. When the method is called with the doubles 10.0 and 20.0, the version of 'doSum' that accepts double arguments is invoked, resulting in the output 'double sum is 30.0'. Therefore, the correct answer is: Integer sum is 30 double sum is 30.0.

Discussion
iSnover

The correct answer is the letter A, there is an overload of the methods. Here's the code: public class Test { public static void doSum(Integer x, Integer y) { System.out.println("Integer sum is " + (x + y)); } public static void doSum(double x, double y) { System.out.println("double sum is " + (x + y)); } public static void doSum(float x, float y) { System.out.println("float sum is " + (x + y)); } public static void main (String[] args) { doSum(10, 20); doSum(10.0, 20.0); } }

yanoolthecool

Answer is actually C Integer sum is 30 double sum is 30.0

Geradine

С public class SumTest { public static void doSum(Integer x, Integer y) { System.out.println("Integer sum is " + (x + y)); } public static void doSum(double x, double y) { System.out.println("Double sum is " + (x + y)); } public static void doSum(float x, float y) { System.out.println("Float sum is " + (x + y)); } public static void main(String[] args) { doSum(10, 20); // Integer sum is 30 doSum(10.0, 20.0); // Double sum is 30.0 doSum(10.0f, 20.0f); // Float sum is 30.0 } }