创建一个people类,包含id、name、age;。 创建一个 student 类,继承people类,包含 school、gradetclass、sno,一个function(输出所有信息);
时间: 2023-12-10 09:40:36 浏览: 72
以下是Python实现:
```python
class People:
def __init__(self, id, name, age):
self.id = id
self.name = name
self.age = age
class Student(People):
def __init__(self, id, name, age, school, grade_class, sno):
super().__init__(id, name, age)
self.school = school
self.grade_class = grade_class
self.sno = sno
def print_info(self):
print(f"ID: {self.id}")
print(f"Name: {self.name}")
print(f"Age: {self.age}")
print(f"School: {self.school}")
print(f"Grade and Class: {self.grade_class}")
print(f"Student Number: {self.sno}")
```
其中,`People`类包含三个属性:`id`、`name`、`age`;`Student`类继承`People`类,并新增了三个属性:`school`、`grade_class`、`sno`。同时,`Student`类还新增了一个`print_info()`方法,可以输出所有信息。
阅读全文