1. 학습
  2. /
  3. 강의
  4. /
  5. Python의 객체 지향 프로그래밍

Connected

연습 문제

비교와 상속

하위 클래스의 객체와 비교하면 어떤 일이 일어날까요? 다음 두 클래스를 살펴보세요:

class Parent:
    def __eq__(self, other):
        print("Parent's __eq__() called")
        return True

class Child(Parent):
    def __eq__(self, other):
        print("Child's __eq__() called")
        return True

Child 클래스는 Parent 클래스를 상속하며, 두 클래스 모두 진단용 출력이 포함된 __eq__() 메서드를 구현합니다.

지침 1/1

undefined XP
    1

질문

다음 코드를 실행하면 어떤 __eq__() 메서드가 호출될까요?

p = Parent()
c = Child()

p == c 

콘솔에서 마음껏 실험해 보세요. 클래스는 이미 정의되어 있어요.

가능한 답변