打印姓名、性别和年龄
package Server;
public class Person {
private String name;
private int age;
private String sex;
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 String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Person(String sex) {
this.sex = sex;
}
public void introduce(){
System.out.println("我叫"+name+",芳龄:"+age+",性别:"+sex);
}
}
输出
package Server;
public class PersonTest {
public static void main(String[] args) {
Person per = new Person("男");
per.setName("小明");
per.setAge(18);
per.setSex("女");
per.introduce();
}
}