71.6k views
1 vote
Given the following method, which of these method calls is valid?

public static void showProduct (int numi, double num2)
int product:
product = numl * (int) num2;
System.out.println("The product is + product); 1

a. showProduct (10.0, 4);
b. showProduct (5.5, 40);
c. showProduct (33.0; 55.0);
d. showProduct (10, 4.5)

User Joey J
by
8.5k points

1 Answer

2 votes

Final answer:

The only valid method call for the showProduct method defined with parameters (int num1, double num2) is option d. showProduct(10, 4.5), as it correctly passes an int as the first argument and a double as the second.

Step-by-step explanation:

The method showProduct is defined with the parameters (int num1, double num2). The method casts num2 to an int within the method body before performing multiplication with num1. Only method calls that pass an integer as the first argument and a double as the second argument will be valid.

Looking at the given method calls:

  • a. showProduct (10.0, 4); is not valid because the first parameter is a double, not an int.
  • b. showProduct (5.5, 40);is not valid for the same reason as (a).
  • c. showProduct (33.0, 55.0); is not valid because both parameters are doubles.
  • d. showProduct (10, 4.5); is a valid call because the first parameter is an int and the second is a double, which fits the method's parameters.

Therefore, the only valid method call from the options provided is d. showProduct (10, 4.5).

User Ankit Sompura
by
7.6k points