Python 클래스 추가 메서드
메소드 추가
예시
클래스 에 호출된 메서드를 추가합니다 welcome
.
Student
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)
부모 클래스의 함수와 이름이 같은 메서드를 자식 클래스에 추가하면 부모 메서드의 상속이 무시됩니다.