重载方法吃
public class Person { String name; int age; void eat(){ System.out.println(name+"正在吃"); } void eat(String food){ System.out.println(name+"正在吃"+food); } void eat(String food,int number){ System.out.println(name+"正在吃"+number+"个"+food); } }
public class Test{ public static void main(String[] args) { Person p=new Person(); p.name="郑飞"; p.age=18; p.eat("烤冷面"); p.eat("烤肠", 2) ; p.eat(); } }