161k views
2 votes
What will be returned from the following method?

public static int methodA(){
double a = 8.5 + 9.5;
return a;}

a. 18.0
b. 18
c 8.0
d. this is an error

1 Answer

5 votes

Final answer:

The answer is d. this is an error because a Java method declared to return an int cannot return a double without explicit casting.

Step-by-step explanation:

The question is asking about the return type of a Java method. The method methodA performs an arithmetic operation with two double values and attempts to return a result of double type as an integer type. However, as Java is strictly typed, it will not automatically convert a double to an integer. Since the return type of the method is declared as int, trying to return a double will cause a compilation error. No conversion or casting is provided in the code, so the answer is d. this is an error.

User Burg
by
7.9k points