클래스 상속을 통해 부모 클래스의 정적 메서드를 호출하는 방법은 무엇인가요?
class Parent:
@staticmethod
def static_method():
print("This is a static method from the parent class")
class Child(Parent):
pass
Child.static_method()
위의 예시에서 Parent
클래스에는 static_method
라는 정적 메서드가 정의되어 있습니다. Child
클래스는 Parent
클래스를 상속받기 때문에, Child
클래스의 인스턴스를 생성하지 않고도 Child.static_method()
를 통해 부모 클래스의 정적 메서드를 호출할 수 있습니다.
해당 코드를 실행하면 “This is a static method from the parent class”라는 출력 결과를 볼 수 있습니다.
참고 자료: