java编写student和person类
时间: 2023-04-27 07:02:58 浏览: 80
武汉大学java期末考试试题和答案
5星 · 资源好评率100%
Java编写Student和Person类:
Person类:
public class Person {
private String name;
private int age;
private String gender;
public Person(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
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;
}
}
Student类:
public class Student extends Person {
private String studentId;
private String major;
public Student(String name, int age, String gender, String studentId, String major) {
super(name, age, gender);
this.studentId = studentId;
this.major = major;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
}
阅读全文