分别定义Person类、Employee类、Student类以及在职研 究生类PartTime_Graduate_Student,并且画出相应的继承层 次图
时间: 2024-02-01 22:14:18 浏览: 92
Person类是一个基类,用于描述一个人的基本信息,如姓名、年龄、性别等。Employee类和Student类都继承自Person类,分别用于描述一个职员和一个学生的信息。PartTime_Graduate_Student类继承自Employee类和Student类,表示一个在职研究生的信息。以下是各个类的定义以及继承关系图:
```
class Person:
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
class Employee(Person):
def __init__(self, name, age, gender, company):
super().__init__(name, age, gender)
self.company = company
class Student(Person):
def __init__(self, name, age, gender, school):
super().__init__(name, age, gender)
self.school = school
class PartTime_Graduate_Student(Employee, Student):
def __init__(self, name, age, gender, company, school):
Employee.__init__(self, name, age, gender, company)
Student.__init__(self, name, age, gender, school)
```
继承关系图:
```
+------------+
| Person |
+-----+------+
|
|
+-----+------+
| Student |
+-----+------+
|
|
+-----+------+
| Employee |
+-----+------+
|
|
+-----+------+
| PartTime |
| Grad. |
+-----------+
```
阅读全文