Write a program in Python to implement the classes designed

Write a program in Python to implement the classes designed above. Using polymorphism, write a function that takes a pet object and displays the type of movement. Write a main function that creates a dog object and calls the function that displays the method of movement of this object. Then creates a fish object and calls the function that displays the method of movement of this object. Calls the main function.

Solution


class Pet:
def __init__(self,name,age):
self.name = name
self.age = age
  
def describeMovement(self):
print(\"Describe Movement\")
def getName(self):
print(\"get name\")
def setName(name):
print(\"set name\")
def getAge(self):
print(\"get age\")
  

class Dog(Pet):
def __init__(self,length,name,age):
self.length = length
self.name =name
self.age = age
super(Pet,self).__init__()
def describeMovement(self):
print(\"Describe Movement\",self.name,self.age,self.length)
def getFurLength(self):
print(\"getFurLength\")
def setFurLength(length):
print(\"setFurLength\")

class Fish(Pet):
def __init__(self,finType,name,age):
self.finType = finType
self.name =name
self.age = age
super(Pet,self).__init__()
  
def describeMovement(self):
print(\"describeMovement\",self.name,self.finType,self.age)
def getfinType(self):
print(\"getfinType\")
def setFinType(finType):
print(\"setFinType\")

if __name__ == \'__main__\':
# x = Pet()
x = Dog(10,\'dog1\',4)
x.describeMovement()
y = Fish(\'type1\',\'fish1\',2)
y.describeMovement()

 Write a program in Python to implement the classes designed above. Using polymorphism, write a function that takes a pet object and displays the type of moveme

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site