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

  • Playable interface: has void play() method
  • Guitar class: play() outputs "Playing guitar"
  • Piano class: play() outputs "Playing piano"
  • In main, create a Playable array 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?