Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. Animals Write a python3 program that defines an Animal base class and three derived classes that inherit from Animal: Cat, Dog, and Fish classes.

image text in transcribed
6. Animals Write a python3 program that defines an Animal base class and three derived classes that inherit from Animal: Cat, Dog, and Fish classes. The Animal base class should take the animal's name (such as rover") as an argument to its constructor. The Animal class should have a method "whoami that returns the name value to the caller. The animal class should have an implementation of the speak" method that prints out The animal refuses to speak- this will be a default method incase no derived class implements it. Three derived classes (Cat, Dog, and Fish) should take name as their constructor argument and in turn pass it to the Animal base class constructor. Extra credit for utilizing python 3.1's new enhanced super() function to avoid hard coding the base class name. The Cat class should implement a "speak" method that prints "Meow!". The Dog class should implement a speak method that prints Woof!". The Fish class should not implement a "speak" method, as fish do not speak. Once the base class and three derived classes are written, create a mainline program/script (in the same file) that creates an empty list named "animals and then appends a Dog named Rover, a Cat named "Hank, and a Fish named "Fred to the list. After the list is populated with the three derived Animal instances, iterate the list and for each animal, print the animal's name and then call it's speak method. The output should appear as follows. This animal's name is Rover Woof! This animal's name is Hank Meow! This animal's name is Fred The animal refuses to speak

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

Define the terms management science and operations research.

Answered: 1 week ago

Question

=+8. Be sure you considered consumer benefits.

Answered: 1 week ago