014-002-006

Method Override: Animal Sounds

Medium

Problem Description

method override: Animal Sounds

In this problem, you will create a program that overrides the makeSound() method in Cat and Dog classes that extend a parent Animal class, and displays each animal's unique sound to standard output.

Learning Objective: Understand how to change parent class behavior using method overriding

Overview

Method overriding allows redefining parent class methods in child classes. This enables different behaviors with the same method name.

Specifications

Create parent class Animal:

  • makeSound() method: outputs "Some sound"

Create child class Cat:

  • Extends Animal
  • Override makeSound(): outputs "Meow"

Create child class Dog:

  • Extends Animal
  • Override makeSound(): outputs "Woof"

In Main class:

  • Create Cat instance and call makeSound()
  • Create Dog instance and call makeSound()

Output Format

Meow
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