← Back to Classes
Question 509
Animals That Speak
Animals That Speak
Write three classes. Animal(name) stores name and has speak(), which prints <name> makes a sound.; Dog and Cat both inherit from Animal, their constructors pass the name up with super().__init__, and each overrides speak to print <name> says Woof. or <name> says Meow. respectively. Do NOT write a main block or any top-level test code; the tests construct the class. Input: one line, a name, which the tests read and use to build an Animal, a Dog and a Cat before calling speak on each in that order, so the output is three lines.
Expected Output:
Rex makes a sound. Rex says Woof. Rex says Meow.
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
ClassesInheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.