Method Override: Animal Sounds
Problem Description
method override: Animal Sounds
Learning Objective: Correctly call overridden methods
In this problem, you will create a program that defines Dog and Cat subclasses extending an Animal superclass, overrides the makeSound() method in each subclass, instantiates the appropriate object based on standard input, and calls the overridden method to display the animal's sound to standard output.
Create an Animal class as the parent class, then implement Dog and Cat subclasses that each override the makeSound() method. Based on the input animal type (dog or cat), instantiate the corresponding object and use polymorphism to invoke the method, displaying each animal's unique sound.
Input
1 line: Animal type (dog or cat)
Output
Sound: [sound]
Example
Input:
dog
Output:
Sound: Woof!
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up