017-002-006
Interface: Multiple Class Implementation
Hard
Problem Description
Interface: Multiple class Implementation
In this problem, you will create a program that defines a Soundable interface, implements it in two classes (Dog and Bell), calls makeSound() on each through a Soundable-type array, and displays the result to standard output.
Learning Objective: Understand how to implement one interface in multiple different classes
Overview
Define an interface (Soundable) representing sound-making ability and implement it in two different classes (Dog and Bell). The same interface can have different behaviors depending on the implementing class.
Specifications
- Soundable interface: Define
makeSound()method - Dog class: Implement Soundable,
makeSound()outputs "Woof!" - Bell class: Implement Soundable,
makeSound()outputs "Ring ring!" - Store Dog and Bell in Soundable-type array and call
makeSound()for each
Output Format
Woof!
Ring ring!
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