더북(TheBook)

정말로 Animal 객체를 만들 수 없는지 확인해 보죠. 우선 코드를 실행하면 결과는 제대로 나옵니다. 그 후에 a = Animal()이라고 입력해 보세요.

eat meat

eat grass

eat meat and grass

>>> a = Animal()

Traceback (most recent call last):

      File "<pyshell#1>", line 1, in <module>

            a = Animal()

TypeError: Can't instantiate abstract class Animal with abstract methods eat


Animal 클래스의 인스턴스를 만들려고 시도했는데 오류가 나네요. 오류 내용을 읽어 보면 추상 메서드인 eat을 가진 추상 클래스 Animal의 인스턴스를 만들 수 없다고 적혀 있습니다.

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.