I will be discussing polymorphism for part three of my Object Oriented Programming series:

  1. Abstraction
  2. Inheritance
  3. Polymorphism – Current Post
  4. Encapsulation


The word polymorphism derives from the Greek words ‘poly’ for many and ‘morphe’ for form, translating to many forms. In programming, polymorphism refers to a variable, object, or function being able to take on different forms. For example, let’s imagine different types of dogs. We have one Dog interface, and multiple classes inheriting from the Dog Interface. A Yorkshire Terrier object can either be a type Yorkshire Terrier or type Dog. That’s polymorphism.

To take it further, imagine the Dog interface has the Bark() function. Each dog has this function, but they all bark differently. If we wanted each dog to bark, we could write the code like this:

Yorkshire Terrier yorkshireTerrier = new YorkShireTerrier();
GoldenRetriever goldenRetriever = new GoldenRetriever();


But what if we had 10 dogs? 20 dogs? Since the dogs are of different types, we have to write a new line calling the bark function on each dog object. This is where polymorphism comes into play.

List Dogs = new List();

Dog yorkshireTerrier = new YorkshireTerrier();
Dog goldenRetriever = new GoldenRetriever();
….10 more dogs here;

forEach(Dog dog in Dogs) {

Since all the dogs are the same type ‘Dog’, we’re able to loop through each dog to call the Bark() function. Each dog is a type of dog, but also their own unique breed. A Yorkshire Terrier is a dog, but also a Yorkshire Terrier that has its own unique bark.


Polymorphism is a powerful tool. It reduces duplication and complications by allowing programmers to treat different objects the same. Objects can inherit from the same interface, but also have their own unique internal structure. Try to find ways you can implement polymorphism into your code.

Share This