编写一个JAVA程序,一个Student类,能够显示学生的姓名,性别,年龄,学号,系部,专业,只使用最基本的与类相关的方法
时间: 2024-05-11 20:19:41 浏览: 86
编写一个JAVA程序,定义一个Student类
5星 · 资源好评率100%
下面是一个基本的JAVA程序,实现了一个Student类,其中包括了学生的姓名,性别,年龄,学号,系部,专业,并提供了相应的get和set方法。
```java
public class Student {
private String name;
private String gender;
private int age;
private String studentId;
private String department;
private String major;
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 getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public static void main(String[] args) {
Student student = new Student();
student.setName("张三");
student.setGender("男");
student.setAge(20);
student.setStudentId("20190001");
student.setDepartment("计算机科学与技术");
student.setMajor("软件工程");
System.out.println("姓名:" + student.getName());
System.out.println("性别:" + student.getGender());
System.out.println("年龄:" + student.getAge());
System.out.println("学号:" + student.getStudentId());
System.out.println("系部:" + student.getDepartment());
System.out.println("专业:" + student.getMajor());
}
}
```
运行结果如下:
```
姓名:张三
性别:男
年龄:20
学号:20190001
系部:计算机科学与技术
专业:软件工程
```
阅读全文