求一Java程序:定义一个类Person此类有成员属性:name,age,sex,有说话say() ,吃饭eat() 行为

2024-11-17 04:50:53
推荐回答(1个)
回答1:

public class Person{
private String name ;
pirvate Integer age;
private String sex;
public Person(String name,Integer age,String sex){
this.name=name;
this.age=age;
this.sex=sex;
}
public void say(){
System.out.println("斗稿我悔散叫“+name+" "+sex+" 年龄:"+age");
}
public void eat(){
System.out.println("我爱吃水果");
}
}
public class Test{
public void static main(String[] args){
Person p = new Person("空前孝xxx",20,"男”):
p.say();
p.eat();
}
}