1、利用构造方法实现方法重载,编写一个学生类:student,类的组成如下: 成员变量:学号,姓名,年龄,专业
时间: 2023-05-17 10:04:15 浏览: 112
以下是实现方法重载的学生类代码:
```java
public class Student {
private String studentID;
private String name;
private int age;
private String major;
public Student(String studentID, String name, int age, String major) {
this.studentID = studentID;
this.name = name;
this.age = age;
this.major = major;
}
public Student(String studentID, String name, int age) {
this.studentID = studentID;
this.name = name;
this.age = age;
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
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 getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
}
```
请问还有什么问题需要我回答吗?
阅读全文