Question 10
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
static int parse(String s) { return Integer.parseInt(s); }
static double parse(String s) { return Double.parseDouble(s); }
public static void main(String[] args) {
System.out.println(parse("42"));
}
}
- A parse must be private
- B The two methods have the same name and parameter list, differing only in return type, which is not a valid overload Correct
- C Double.parseDouble does not exist
- D main cannot call static methods
Correct Answer: Option B
Give them different names, such as parseInt and parseDouble.
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!