Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?


Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?


a) foo(0, 0.1);

b) foo(0 / 1, 2 * 3);

c) foo(0);

d) foo( );

e) foo(1 + 2, 3 * 0.1);

Answer: b. Explanation: The only legal method call is one that passes two int parameters. In the case of answer b, 0 / 1 is an int division (equal to 0) and 2 * 3 is an int multiplication. So this is legal. The answers for a and e contain two parameters, but the second of each is a double. The answers for c and d have the wrong number of parameters.