编写一个封装学生信息的JavaBean,类名为StudentFrom,类中包含学号、姓名、性别、年龄、联系电话、E-mail、住址等属性
时间: 2023-11-08 16:50:38 浏览: 188
下面是一个简单的JavaBean示例,封装了学生的基本信息:
```java
public class StudentForm {
private String id; // 学号
private String name; // 姓名
private String gender; // 性别
private int age; // 年龄
private String phone; // 联系电话
private String email; // E-mail
private String address; // 住址
// 构造方法
public StudentForm(String id, String name, String gender, int age, String phone, String email, String address) {
this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
this.phone = phone;
this.email = email;
this.address = address;
}
// getter/setter方法
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
```
以上代码中,我们定义了一个包含学生信息的JavaBean类StudentForm,它有学号、姓名、性别、年龄、联系电话、E-mail、住址等属性,同时提供了构造方法和getter/setter方法,以方便对学生信息进行封装和访问。
阅读全文