Java 学习笔记(1)
方法重载
方法重载仅仅与参数列表有关,与返回值类型以及参数名无关
public static void test(int a, int b) {};
//参数个数不同
public static void test(int a, int b, int c) {};
//参数类型不同
public static void test(int a, double b) {};
//参数类型的顺序不同
public static void test(double a, int b) {};
以上写法为正确的方法重载,下列所示为错误情况
//参数名称不同,不能称之为重载
public static void test(int x, int y) {};
//返回值类型不同,不能称为重载
public static int test(int a, int b) {};