Dolphin

Report a typo

Everybody knows that dolphins are mammals. Below is a class Mammal with 2 methods: __init__ and greet. __init__ defines the attribute bio_class with the value mammal, while greet prints out I am a mammal!.

Create a class Dolphin. It should be a child class of the class Mammal and have the same __init__. However, you need to override the greet method so that in addition to the I am a mammal! it prints I am a dolphin!. Use the super() function. You don't need to define any additional attributes in the class Dolphin.

Here's an example of this:

dolph = Dolphin()
dolph.greet()
# I am a mammal!
# I am a dolphin!

Pay attention to the order of actions in the method. Look closely at the expected output and think about what should go first: the calling of the superclass method or printing the new message?
Write a program in Python 3
class Mammal:
def __init__(self):
self.bio_class = "mammal"

def greet(self):
print("I am a {}!".format(self.bio_class))


# create class Dolphin here
___

Create a free account to access the full topic