import abc
class Animal(metaclass=abc.ABCMeta):
@abc.abstractmethod
def eat(self):
pass
@abc.abstractmethod
def drink(self):
pass
@abc.abstractmethod
def speak(self):
pass
class Dog(Animal):
def eat(self):
print('dog is eating')
def drink(self):
print('dog is drinking')
def speak(self):
print('dog is speaking')
class Cat(Animal):
def eat(self):
print('cat is eating')
d = Dog()
d.drink()
c = Cat()
c.drink()
C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe “C:/Users/user/PycharmProjects/hellow python/test.py”
dog is drinking
Traceback (most recent call last):
File “C:/Users/user/PycharmProjects/hellow python/test.py”, line 34, in
c = Cat()
TypeError: Can’t instantiate abstract class Cat with abstract methods drink, speak
Process finished with exit code 1