# There are Two ways to use abstractmethod #
# First Way #
from abc import ABCMeta,abstractmethod
class Dog(metaclass=ABCMeta) : # Super class #
@abstractmethod # Decorator #
def barking (self) :
return 0
class BullDog(Dog) : # BullDog class is Inherited by Dog class #
def barking(self):
return "Quite/Mild Barking"
class Beagle(Dog) :
def barking(self):
return "Loud/Violent Barking"
bulldog = BullDog()
beagle = Beagle()
print(bulldog.barking())
print(beagle.barking())
# Second Way #
from abc import ABC,abstractmethod
from abc import ABCMeta,abstractmethod
class Dog(ABC) : # Super class #
@abstractmethod # Decorator #
def barking (self) :
return 0
class BullDog(Dog) : # BullDog class is Inherited by Dog class #
def barking(self):
return "Quite/Mild Barking"
class Beagle(Dog) :
def barking(self):
return "Loud/Violent Barking"
bulldog = BullDog()
beagle = Beagle()
print(bulldog.barking())
print(beagle.barking())
Comments
Post a Comment