方法的重载:多个方法的名称一样,但参数列表不一样。不一样的地方体现在,形参的个数,形参的数据类型。
public class subject03OverLoad {
public static void main(String[] args) {
cbi('中', '国');
cbi('中', '国', '强');
cbi('中', '国', '很', '强');
cbi('中', 2);
cbi(2, '中');*/
}
public static void cbi(char a, char b) {
System.out.printf("%c%c\n", a, b);
}
public static void cbi(char a, char b, char c) {
System.out.printf("%c%c%c\n", a, b, c);
}
public static void cbi(char a, char b, char c, char d) {
System.out.printf("%c%c%c%c\n", a, b, c, d);
}
public static void cbi(char a, int b) {
System.out.printf("%c%d\n", a, b);
}
public static void cbi(int a, char b) {
System.out.printf("%d%c\n", a, b);
}
}