Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.List;
public class Main {
static int total(List<Integer> nums) { return nums.size(); }
static int total(List<String> words) { return words.size(); }
public static void main(String[] args) {
System.out.println(total(List.of(1, 2)));
}
}
- A total must return long
- B Both methods erase to total(List), so they clash; give them different names Correct
- C Static methods cannot be overloaded
- D List.of needs a type argument
Correct Answer: Option B
javac: "name clash: total(List
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!