定义一个学生类student ,继承自Chinese,并实现接口People,在方法complexion中输出“complexion is yellow.”
时间: 2023-12-03 13:41:58 浏览: 30
下面是一个 Python 代码的示例,实现了上述要求:
```python
class Chinese:
def __init__(self, name, age):
self.name = name
self.age = age
def speak_chinese(self):
print("我是中国人,我会说中文。")
class People:
def complexion(self):
print("complexion is yellow.")
class Student(Chinese, People):
def __init__(self, name, age, school):
super().__init__(name, age)
self.school = school
def study(self):
print(f"{self.name} 在 {self.school} 学习。")
# 测试
s = Student("小明", 18, "清华大学")
s.speak_chinese() # 我是中国人,我会说中文。
s.complexion() # complexion is yellow.
s.study() # 小明 在 清华大学 学习。
```
在这个示例中,我们定义了一个 Chinese 类作为基类,它有一个方法 speak_chinese(),表示说中文。然后我们定义了一个 People 接口,其中有一个方法 complexion(),表示肤色。最后我们定义了一个 Student 类,它继承自 Chinese 类,并实现了 People 接口。它有一个方法 study(),表示学习。在 complexion() 方法中,我们输出了“complexion is yellow.”,以满足题目要求。