编写一个学生类Student, 1、该类中包括name age gender phone address email成员变量,其中age为整型变量,其他的都为String类型的变量
时间: 2024-05-08 20:16:10 浏览: 71
2、该类中包括构造函数和无参构造函数,以及getter和setter方法
3、重写toString方法,返回该学生对象的信息字符串形式
以下是代码实现:
```
public class Student {
private String name;
private int age;
private String gender;
private String phone;
private String address;
private String email;
public Student(String name, int age, String gender, String phone, String address, String email) {
this.name = name;
this.age = age;
this.gender = gender;
this.phone = phone;
this.address = address;
this.email = email;
}
public Student() {
}
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 getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", gender='" + gender + '\'' +
", phone='" + phone + '\'' +
", address='" + address + '\'' +
", email='" + email + '\'' +
'}';
}
}
```
阅读全文