方法重载
- 在同一个了类中 方法参数列表不同的同名方法,这种表现形式我们称之为方法重载
- 相同的方法名,参数列表不同, 参数的数量不同, 参数的数据类型不同,都成立。
- 此处参数的数据类型 指的相同参数位置上的数据类型
public class Demo02 {
public static void main(String[] args) {
eat();
eat("核桃");
eat("核桃", 6);
eat(5, "包子");
}
public static void eat() {
System.out.println("吃吃吃");
}
public static void eat(String food) {
System.out.println("吃" + food);
}
public static void eat(String food, int count) {
System.out.println("foodcount吃" + count + "个" + food);
}
public static void eat(int count, String food) {
System.out.println("countfood吃" + count + "个" + food);
}
}
