用JAVA创建一个学生类,包含姓名,年龄,学号,班级,入学年
时间: 2024-05-09 19:18:04 浏览: 108
java课程设计-学生学籍管理系统
份等属性,要求能够通过构造方法或set方法设置属性值,并且能够通过get方法获取属性值。代码如下:
```
public class Student {
private String name;
private int age;
private String studentId;
private String className;
private int entranceYear;
public Student(String name, int age, String studentId, String className, int entranceYear) {
this.name = name;
this.age = age;
this.studentId = studentId;
this.className = className;
this.entranceYear = entranceYear;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public void setClassName(String className) {
this.className = className;
}
public void setEntranceYear(int entranceYear) {
this.entranceYear = entranceYear;
}
public String getName() {
return this.name;
}
public int getAge() {
return this.age;
}
public String getStudentId() {
return this.studentId;
}
public String getClassName() {
return this.className;
}
public int getEntranceYear() {
return this.entranceYear;
}
}
```
希望我的回答能够解决您的问题!
阅读全文