Given:
What is the result?
A. Good Day!
Good Luck!
B. Good Day!
Good Day!
C. Good Luck!
Good Day!
D. Good Luck!
Good Luck!
E. Compilation fails
Given:
What is the result?
A. Good Day!
Good Luck!
B. Good Day!
Good Day!
C. Good Luck!
Good Day!
D. Good Luck!
Good Luck!
E. Compilation fails
Option A.
public class Test {
public static String doMsg(char x) {
return “Good Day!”;
}
public static String doMsg(int y) {
return “Good Luck!”;
}
public static void main(String[] args) {
char x = 8;
int z = ‘8’;
System.out.println(doMsg(x));
System.out.print(doMsg(z));
}
}
Output:
Good Day!
Good Luck!
Explanation:
The variable “x” is assigned the ASCII sign of code 8 (“\b” or “BS” – non printable! sign) and enters the method doMsg(char x).
The variable “z” is assigned the ASCII code of the sign “8” (which is 56) and enters the method doMsg(int y).
NOTE: this example wouln’t compile, if “z” was assigned a two digit number (no ASCII code, not char type).