0% found this document useful (0 votes)
871 views1 page

Abstract Class 1

The document defines an abstract Animal class with an abstract say method. It then defines a Dog class that inherits from Animal and implements the say method to return the string "I speak Booooo". The code checks that Animal is an abstract class, say is an abstract method, Dog inherits from Animal, and calls the say method on a Dog instance to output "I speak Booooo".

Uploaded by

Senthil Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
871 views1 page

Abstract Class 1

The document defines an abstract Animal class with an abstract say method. It then defines a Dog class that inherits from Animal and implements the say method to return the string "I speak Booooo". The code checks that Animal is an abstract class, say is an abstract method, Dog inherits from Animal, and calls the say method on a Dog instance to output "I speak Booooo".

Uploaded by

Senthil Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

===================================================================================

===================================================================================
===================================================================================
===================================================================================
====================================================

define an abstact class Animal with an abstract method say


define a child lass dog derived from animal aslo define a mehtod say wiich prints
the message 'I speak Booooo'
from abc import ABC, abstractmethod

# Define the abstract class 'Animal' below


# with abstract method 'say'
class Animal(ABC):
@abstractmethod
def say(self):
pass

# Define class Dog derived from Animal


# Also define 'say' method inside 'Dog' class
class Dog(Animal):
def say(self):
return "I speak Booooo"

if __name__ == '__main__':

if issubclass(Animal, ABC):
print("'Animal' is an abstract class" )

if '@abstractmethod' in inspect.getsource(Animal.say):
print("'say' is an abstract method")

if issubclass(Dog, Animal):
print("'Dog' is dervied from 'Animal' class" )

d1 = Dog()
print("Dog,'d1', says :", d1.say())

===================================================================================
===================================================================================
===================================================================================
=======================================

You might also like