创建person类,并设置name,sex及age三个private属性,设置无参构造方法和带参数的构造方法;设置setname(),setsex(),setage()方法给三个属性赋值,并用getn
时间: 2023-04-26 19:01:10 浏览: 322
设计一个Personal类
ame(),getsex(),getage()方法获取属性值。代码如下:
```
public class Person {
private String name;
private String sex;
private int age;
public Person() {
}
public Person(String name, String sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public void setname(String name) {
this.name = name;
}
public void setsex(String sex) {
this.sex = sex;
}
public void setage(int age) {
this.age = age;
}
public String getname() {
return name;
}
public String getsex() {
return sex;
}
public int getage() {
return age;
}
}
```
阅读全文