定义一个基类有姓名、性别、年龄;再由基类派生出教师类和学生类,教师类增加工号、职称和工资,学生类增加学号、班级、专业和入学成绩;由学生类和教师类派生在职研究生类和在读教师类,在职研究生类增加工作单位。
时间: 2024-06-06 17:07:55 浏览: 75
class Person:
def __init__(self, name, gender, age):
self.name = name
self.gender = gender
self.age = age
class Teacher(Person):
def __init__(self, name, gender, age, work_id, title, salary):
super().__init__(name, gender, age)
self.work_id = work_id
self.title = title
self.salary = salary
class Student(Person):
def __init__(self, name, gender, age, student_id, class_name, major, score):
super().__init__(name, gender, age)
self.student_id = student_id
self.class_name = class_name
self.major = major
self.score = score
class WorkingGraduateStudent(Student):
def __init__(self, name, gender, age, student_id, class_name, major, score, work_unit):
super().__init__(name, gender, age, student_id, class_name, major, score)
self.work_unit = work_unit
class StudyingTeacher(Teacher):
def __init__(self, name, gender, age, work_id, title, salary, major):
super().__init__(name, gender, age, work_id, title, salary)
self.major = major
阅读全文