# Mortein Killer’s Polymorphism [POLYMORPHISM Simplified]

Hi all. The concept of polymorphism is simple once you catch it. Here is a simple analogy on polymorphism for you.

This is Sri, once again with another amazing analogy that will clear all the doubts in the concept of Polymorphism. Looking at the title, you might be thinking whether this is a crime story 🙂 However, it is in one way! But the killer in the title is Mortein Mosquito the world-famous Cockroach killer.

Many of us would have seen this ad “Black Hit for Mosquito and Red Hit for Cockroach“.

How many of you, did actually use the red Mortein for the cockroach and still wondered why the cockroach is still alive? Obviously, I am on your side. In those scenarios, we start pondering on why the hell do they have separate bottles, anyways? 🙁

Note: I did not get Red bottle with mosquito image so adjust with green 🙂

Now coming to our topic polymorphism. This would be the case for the users of your code if no polymorphism exists.

(Note: You can also see my previous post about Abstraction in OOPS in this post “Ammi Kallum Abstraction um”)

Suppose, somebody, ask you to write a math library. Imagine it includes functions like addition, subtraction, etc. They will use the library for their calculator program.

The day comes, you delivered the code and along with given 100 pages document saying, Call addFloat for adding float numbers, addInt for adding integers, etc. Hey, dear programmer for just adding two numbers how many pages do I have to refer to find the correct function name. Because to add float, you have written function with name addFloat, for integers addInt.

This is really cumbersome and irritating for the team and the project also appears too big. Even for small projects, this is very difficult for development and maintenance.

To overcome this issue, compile-time polymorphism came into the picture. Don’t name the functions differently. If the function is to add, just name the function as add again. The function for adding integers and float will have the same names. But for the compiler to identify it’s not a redefinition, we have to give some identification marks like-

1.Make the datatype of the function parameters different or

2.Make a difference in the number of parameters.

So that compiler can identify this as a polymorph of add function. But you may be asking how a compiler is doing this magic.

The secret sauce is Name Mangling, even though we name both the functions as add for adding float and adding integers. The compiler will internally change the name of the function so that it will become 2 different functions for the compiler.

NameMangled functions

These are just samples!

So whenever we call add, the compiler will look for the type of parameters and call the respective the NameMangled add function.

We can see Run Time Polymorphism in our next post.

I heard that hitting Like is good for health 🙂 So just hit the like button. And for more technical videos visit us GUVI.

Thanks,

Sri.

With10 +yrs of experience in the software industry, I am very passionate about coding and love to teach others. I have considerably good experience in languages like C, C++, VC++, Java, PHP.

Now a full-time entrepreneur and taking care of GUVI.

Contact Form

By clicking 'Submit' you Agree to Guvi Terms & Conditions.

Our Learners Work at

Our Popular Course

## Our Live Classes

### Full Stack Development Program (FSD)

Learn Javascript, HTML, CSS, Java, Data Structure, MongoDB & more

### IIT-M Advanced Programming & Data Science Program

Learn Python, Machine Learning, NLP, Tableau, PowerBI & more

### Automation and Testing Program

Learn Selenium, Python, Java, Jenkins, Jmeter, API Testing & more

### Cybersecurity & Ethical Hacking Program

Learn Networking, Security Testing, IAM, Access Management & more

## Related Articles

Hello Friends, this is Arun Prakash, the founder of GUVI. By and large the approach towards getting a job and