In this we are going to see a program about Implementation of Abstract Class in Python Programming Language.
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def sound(self):
print("Animal Sounds")
pass
class Cat(Animal):
def sound(self):
print("Cat meows")
class Dog(Animal):
def sound(self):
print("Dog barks")
class Snake(Animal):
def sound(self):
super().sound()
print("Snake hisses")
s = Snake()
s.sound()
# The following lines will give out an error: as we cannot instantiate an abstract class containing an abstract method
# a = Animal()
# a.sound()
# Coded by Saahil
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP