017-005-009
Interface Type References
Medium
Problem Description
Interface Type References
In this problem, you will create a program that defines a Playable interface, implements it in Guitar and Piano classes, and uses an interface-typed array to call each instrument's play method polymorphically, displaying the results to standard output.
Learning Objective: Understand how to reference objects using interface type variables and utilize polymorphism
Overview
Create Guitar and Piano classes implementing Playable interface, and manage them in an interface-typed array.
Specifications
Playableinterface: hasvoid play()methodGuitarclass:play()outputs "Playing guitar"Pianoclass:play()outputs "Playing piano"- In
main, create aPlayablearray containing Guitar and Piano - Loop through the array and call play method on each instrument
Output Format
Playing guitar
Playing piano
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