81.1k views
4 votes
Suppose that you have created a program with only the following variables.

int x = 2
int y = 3

Suppose that you also have a method with the following header: public static void mathMethod(int x) Which of the following method calls are legal?
a. mathMethod(x); mathMethod (12)
b. mathMethod(y); g. mathMethod(12.2)
c. mathMethod(x, y); mathMethod (
d. mathMethod (x + y); mathMethod(a)
e. mathMethod(12L); mathMethod(a / w)

1 Answer

2 votes

Complete Question:

Suppose that you have created a program with only the following variables.

int x = 2

int y = 3

Suppose that you also have a method with the following header: public static void mathMethod(int x) Which of the following method calls are legal?

a. mathMethod(x);

b. mathMethod(y);

c. mathMethod(x, y);

d. mathMethod (x + y);

e. mathMethod(12L);

f. mathMethod (12);

g. mathMethod(12.2);

h. mathMethod (

i. mathMethod(a)

j. mathMethod(a / w

Answer:

The following options are legal

A mathMethod(x);

B mathMethod(y);

D mathMethod (x + y);

F mathMethod (12)

Step-by-step explanation:

The method mathMethod(int x) Can only receive an int as argument when called.

The four options above provides an int variable to the method call. The other options do not provide an int variable.

E provides a long variable type

G provides a double variable type

H has a syntax error

I the variable a is not defined

J Both a and w are not defined

User Manshu
by
5.7k points