014-005-006
Method Override
Easy
Problem Description
method override
In this problem, you will create a program that defines an Animal class and a Cat class, overrides the parent class's makeSound() method in the child class, and displays "[name] says: Meow!" to standard output.
Learning Objective: Understand how to override parent class methods in child class
Overview
Create a program that reads a cat's name from standard input and displays its sound through an overridden method.
Specifications
- Define a
namefield, constructor, andmakeSound()method in Animal class (outputs "[name] says: Animal sound") - Cat class extends Animal and overrides
makeSound()(outputs "[name] says: Meow!") - In Main class, read the name using Scanner, create a Cat instance, and call
makeSound()
Input Format
Cat's name (1 line)
Output Format
[name] says: Meow!
Example
Input: Whiskers
Output: Whiskers says: Meow!
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