oop Polymorphism Introduction


Polymorphism is one of the basic concepts in OOP (Object Oriented Programming). Main idea of the polymorphism is that an object have the ability to take on different forms. To achieve that (polymorphism), we have two main approaches.

  1. Method overloading

    • Occures when there are two or more methods with the same name, with different input parameters. The return type should be the same for all the methods with the same name
  2. Method overriding

    • Occures when child object uses same method definition (same name with same parameters), but have different implementations.

Using these two approaches we can use the same method/function to behave differently. Let's see more details on this in following examples.