Polymorphism explained simply!

OOP | For beginners | Dynamic vs. Static

Static Polymorphism

This is also mentioned as Compile-Time polymorphism, Static binding, Compile-Time binding, Early binding and Method overloading. Here having many forms is happening in the same class.

If I explain this SIMPLY..

This is actually method overloading. Method overloading is having more than one method with the same method name but with different arguments (return type may or may not be same). Here when calling the methods compiler compiler choose which method to call depending on the parameters passed when calling. This happens at compile-time.

Eg: Java code

class Calculator { void add(int a, int b) { System.out.println(a+b); } void add(int a, int b, int c) { System.out.println(a+b+c); }}public class Demo { public static void main(String args) { Calculator calculator = new Calculator(); // method with 2 parameters is called calculator.add(10, 20); //output: 30 // method with 3 parameters is called calculator.add(10, 20, 30); //output: 60 }}

Some people say method overloading is not truely polymorphism. But I think it can be categorize as a type of polymorphism since in method overloading there is a method in many forms.

Hope this helped in understanding polymorphism simply.

Cheeers! 😀

Here are some useful links

  • Method overriding
  • Method overloading
  • Types of polymorphism
  • Difference between Runtime Polymorphism and Compile time Polymorphism

Leave a Reply

Your email address will not be published. Required fields are marked *