Primitive Type Method Call Error
Which of the following best explains why the ConditionError class shown below will fail to compile?
public class ConditionError {
public static int countRecursively(int n) {
if(n.equals(0))
return 0;
else
return n + countRecursively(n - 1);
}
public static void main(String[] args) {
System.out.println(countRecursively(5));
}
}
A
The code incorrectly attempts to call the equals method on a primitive int, which is not allowed.
B
The base case condition is logically flawed.
C
The method countRecursively should return a boolean value.
D
The arithmetic operator in the recursive call is misused.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE