用java设计一个名为person的类和它的两个子类名为Student和Employee的子类,Employee的子类又有子类教员类Faculty和职员类Staff。每个人都有姓名、地址、电话号码、和电子邮件地址。学生有班级状态(大一)
时间: 2024-02-12 12:08:33 浏览: 110
好的,以下是Java代码实现:
```java
public class Person {
private String name;
private String address;
private String phoneNumber;
private String email;
public Person(String name, String address, String phoneNumber, String email) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
this.email = email;
}
// Getters and Setters
// ...
@Override
public String toString() {
return "Name: " + name + "\nAddress: " + address + "\nPhone number: " + phoneNumber + "\nEmail: " + email;
}
}
public class Student extends Person {
private String gradeStatus;
public Student(String name, String address, String phoneNumber, String email, String gradeStatus) {
super(name, address, phoneNumber, email);
this.gradeStatus = gradeStatus;
}
// Getters and Setters
// ...
@Override
public String toString() {
return super.toString() + "\nGrade status: " + gradeStatus;
}
}
public class Employee extends Person {
public Employee(String name, String address, String phoneNumber, String email) {
super(name, address, phoneNumber, email);
}
// Getters and Setters
// ...
}
public class Faculty extends Employee {
public Faculty(String name, String address, String phoneNumber, String email) {
super(name, address, phoneNumber, email);
}
// Getters and Setters
// ...
}
public class Staff extends Employee {
public Staff(String name, String address, String phoneNumber, String email) {
super(name, address, phoneNumber, email);
}
// Getters and Setters
// ...
}
```
以上就是一个名为`Person`的基类和三个子类`Student`、`Employee`和`Faculty`的Java实现。
其中,`Student`类有一个额外的属性`gradeStatus`,表示学生的班级状态。而`Employee`类没有额外的属性,它的两个子类`Faculty`和`Staff`都没有额外的属性,只是继承了基类`Person`的属性。这里只给出了类的定义和属性,需要根据具体的需求添加方法等。
阅读全文