前情提要
Java面向对象的三个基本特征:继承、封装和多态;多态主要体现在重载和重写;
示例代码
无意间看到这样一个问题,为了方便直观,就用代码来描述问题,有这样一个类:
public class OverloadPriority {
public static void print(Object arg) {
System.out.println("parameter type = Object");
}
public static void print(int arg) {
System.out.println("parameter type = int");
}
public static void print(long arg) {
System.out.println("parameter type = long");
}
public static void print(double arg) {
System.out.println("parameter type = double");
}
public static void print(float arg) {
System.out.println("parameter type = float");
}
public static void print(char arg) {
System.out.println("parameter type = char");
}
public static void print(Character arg) {
System.out.println("parameter type = Character");
}
public static void print(char... arg) {
System.out.println("parameter type = char...");
}
public static void print(Serializable arg) {
System.out.println("parameter type = Serializable");
}
public static void print(Comparable<?> arg) {
System.out.println("parameter type = Comparable");
}
public static void main(String[] args) {
// int
print('g');
}
}