class Person
{
private String name;
private int age;
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age=age;
}
public Person(String name,int age){
this.name=name;
this.age=age;
}
public void eat(Apple apple){
System.out.println(age+"岁"+name+"吃了"+apple.getColor()+"苹果");
}
}
public class Apple
{
private String color;
public String getColor(){
return color;
}
public String setColor(){
this.color=color;
}
public Apple(String color){
this.color=color;
}
public static void main(String [] args){
Person p1=new Person("张三",18);
Person p2=new Person("李四",20);
Apple a1=new Apple("红");
Apple a2=new Apple("青");
p1.eat(a1);
}
43行 缺少返回值,大神麻烦帮忙看看,小弟新手
------解决思路----------------------
set方法是void类型把