1.DEFs of OVERLOAD:声明在同一个类中,方法名相同但方法的参数列表不同的方法构成方法重载。
其中,参数列表不同分为1️⃣参数的个数不同2️⃣参数类型不同
2.e.g.
public class Overload {
public static void main(String[] args) {
Overload o=new Overload();
o.AllenIverso("a");
o.AllenIverson();
o.AllenIverson(23);
o.AllenIverson(23,24)
}
//如下四个方法构成方法重载
public void AllenIverson(){
System.out.println("小艾可是96年黄金一代的状元啊");
}
public void AllenIverson(int sxai){
System.out.println("I am what I am");
}
public void AllenIverson(int sxai,int kobe){
System.out.println("Only the strong survive");
}
public void AllenIverso(String sxai){
System.out.println("Allen Iverson was the Best Bball player amid the Michael Jordan Dynasty");
}
}
编译运行:
Allen Iverson was the Best Bball player amid the Michael Jordan Dynasty
小艾可是96年黄金一代的状元啊
I am what I am
Only the strong survive