方法重载Overload
为什么学习方法重载?
使用重载只是方便我们不用记住很多方法名字而已!
//-----没有重载-------------
public class Demo01 {
    public static void main(String[] args) {
        addInt(10,20);
        addByte((byte)1,(byte)2);
        addDouble(1,2);
    }
    //1.计算两个int的和?
    public static void addInt(int a,int b){
        System.out.println(a+b);
    }
    //2.计算两个byte的和?
    public static void addByte(byte a,byte b){
        System.out.println(a+b);
    }
    //3.计算两个double的和?
    public static void addDouble(double a,double b){
        System.out.println(a+b);
    }
}
//-------使用重载------------- public class Demo02 { public static void main(String[] args) { add(10,20); add((byte)1,(byte)2); add(1,2.0); } //1.计算两个int的和? public static void add(int a,int b){ System.out.println(a+b); } //2.计算两个byte的和? public static void add(byte a,byte b){ System.out.println(a+b); } //3.计算两个double的和? public static void add(double a,double b){ System.out.println(a+b); } }
方法重载语法:
在同一个类中,两个及两个以上的方法,方法名完全一致,参数列表不一致,跟其他任何内容无关!
参数列表不一致:
    1.参数个数不同
  2.参数类型不同
  3.参数的类型的顺序不同
举例如下: