017-005-009
Interface Type References
Medium
Problem Description
Interface Type References
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?
