Question: 1. Create two public classes: Mammal and Bird. Each should inherit from the Animal class shown below. For each new class, override the giveBirth method
1. Create two public classes: Mammal and Bird. Each should inherit from the Animal class shown below.
For each new class, override the giveBirth method to produce the following output:
For the Mammal class, the method should return: "I give live birth"
For the Bird class, the method should return "I lay eggs"
class Animal: """This is an animal""" def giveBirth(self): """Return the birthing method""" return "I don't know how"
2.
Given the Bird class below, construct the base class Animal from which it inherits.
For the Animal class, you will need:
Two properties name and birthMethod (both strings) with a corresponding initializer.
A method named giveBirth (no parameters other than self) that returns the value of the birthMethod property.
class Bird(Animal): """This is a bird""" def __init__(self, name, flies): """Initializer""" super().__init__(name, "eggs") self.flies = flies
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
