Polymorphism

example, imagine a program that plays audio files.

  • A media player might need to load an AudioFile object and then play it.
  • We’d put a play() method on the object, which is responsible for decompressing or extracting the audio and routing it to the sound card and speakers.
  • The act of playing an AudioFile could feasibly be as simple as:
    audio_file.play()
  • However the process of decompressing and extracting an audio file is very different for different types of files. The .wav files are stored uncompressed, while .mp3, .wma, and .ogg files all have very different compression algorithms.

output:—
.

Open chat