Consider the following method.
public double secret(int x, double y) { return x/2.0; }
Which of the following lines of code, if located in a method in the same class as secret, will compile without
error?
int result = secret(4, 4);
double result = secret(4.0, 4);
int result = secret(4, 4.0);
double result = secret(4.0, 4.0);
double result = secret(4, 4.0);

Respuesta :

Answer:

The answer to this question is given below in the explanation section.

Explanation:

Consider the following method.

public double secret(int x, double y)

{

return x/2.0;

}

The return type of this function is double, so where it will store the result in a variable, that variable should be of double type. So, among given options, the correct option is double result = secret(4, 4.0);

All others options are incorrect and will give the error.

for example:

int result = secret(4, 4);

in it, the function secret is accepting first integer and second double parameters, while you are passing all integer variables.

int result = secret(4, 4.0);

you are not allowed to store double value into integer.

double result = secret(4.0, 4.0); in it you are passing incorrect types of parameter.