October 15, 2002
Tech Tips Quiz
[http://developer.java.sun.com/developer/Quizzes/techtips3/index.html]
public class OverDemo1 {
// overload methodA between short/int
static void methodA(short s) {
System.out.println(
"methodA(short) called");
}
static void methodA(int i) {
System.out.println("methodA(int) called");
}
// overload methodB between float/double
static void methodB(float f) {
System.out.println(
"methodB(float) called");
}
static void methodB(double d) {
System.out.println(
"methodB(double) called");
}
public static void main(
String args[]) {
// call methodA with char argument
methodA('a'); //methodA(int) called
// call methodB with int argument
methodB(Integer.MAX_VALUE); // methodB(float) called
}
}
Why does methodA('a') call methodA(int i)?
How about char and int and short?
int is 32bit,char and short is 16bit.