Phương pháp Thêm lớp trong Python
Thêm phương pháp
Thí dụ
Thêm một phương thức được gọi welcome
vào
Student
lớp:
class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.graduationyear
= year
def welcome(self):
print("Welcome",
self.firstname, self.lastname, "to the class of", self.graduationyear)
Nếu bạn thêm một phương thức trong lớp con có cùng tên với một hàm trong lớp cha, thì sự kế thừa của phương thức mẹ sẽ bị ghi đè.