class Student {
private String name;
private int age;
private char sex; //成员变量
public Student(){}
public Student(String name, int age, char sex){ //构造方法
this.name=name;
this.sex=sex;
this.age=age;
}
public void setAge(int age){ // 成员方法
this.age=age;
}
public int getAge(){
return age;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}public void setSex(char sex){
this.sex=sex;
}
public int getSex(){
return sex;
}
public void show(){
System.out.println(name+sex+"士今年"+age+"岁");
}
}
class StudentDemo{
public static void main(String[] args) {
Student s =new Student("张三",13,'男');
s.show();
}
}
|
|