In the JQuest Mock Exam, the following question puzzles me:
Consider the following class
1. class Tester {
2. void
test (int i) { System.out.println ("int version"); }
3. void test (
String s) { System.out.println ("String version"); }
4.
5. public static void main (String args[]) {
6. Tester c = new Tester ();
7. char ch = 'p';
8. c.test (ch);
9. }
10. }
Which of the following statements below is true?(Choose one.)
a. Line 3 will not compile, because void methods cannot be overridden.
b. Line 8 will not compile, because there is no conversion of test() that takes a char argument.
c. The code will compile and produce the following output "int version"
d. The code will compile and produce the following output "String version"
The answer is 'The code will compile and produce the following output "int version"'
I checked it in a test class, and it's correct, but why is this true? How does
Java decided to go to the int version and not the String version?