>>> from abc import ABCMeta
>>> from abc import abstractmethod
>>>
>>> class Animal(metaclass=ABCMeta):
def __init__(self):
pass
@abstractmethod
def eat(self):
pass
>>> class Human(Animal):
def __init__(self):
pass
>>> h = Human()
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
h = Human()
TypeError: Can't instantiate abstract class Human with abstract methods eat # 상속받은 추상메소드를 구현하지 않아 에러 발생!!!!
# 추상메소드를 구현한다.
>>> class Human(Animal):
def __init__(self):
pass
def eat(self):
print("Human eat")
# 추상클래스는 인스턴스화 할 수 없다.
>>> a = Animal()
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
a = Animal()
TypeError: Can't instantiate abstract class Animal with abstract methods eat
>>>
>>> h = Human()
>>> h.eat()
Human eat # 정상작동한다.
>>>
추상클래스 (Abstract class)
|
2020.02.01 20:16:39
|
2020.03.08 03:06:36
|
413
|
Aiden
Total of Attached file
0.00 Bytes of 0 files
2020.04.29
2020.04.28
2020.03.07
2020.02.29
2020.02.16
2020.02.01
2020.02.01
2020.01.24
2020.01.18
2020.01.17
2020.01.12