What is the difference between function polymorphism and overloading?

Asked By 0 points N/A Posted on -
qa-featured

 

I'm still not clear about the distinction between 'polymorphism' and 'overloading'.

Could you please let me know how to differentiate between the two?

Thanks.

SHARE
Best Answer by y2caye
Best Answer
Best Answer
Answered By 0 points N/A #91793

What is the difference between function polymorphism and overloading?

qa-featured

Short answer: 
They are the same. 

Long Answer, (and yet less revealing): 

Polymorphism is simply the ability to have many different methods (Or functions, for those who are used to C-Type programs) to have the same name, but act differently depending on the type of parameters that were passed to the function. 

So for example, we may have a method called punch, which accepts no parameters at all, and returns an integer: 

public int punch() 
{ 
return 3; 
} 

We could also have a method named punch that accepts a String and returns a boolean. 

public boolean punch(String poorGuyGettingPunched) 
{ 
if(poorGuyGettingPunched.equals("joe")) 
{ 
System.out.println("sorry Joe"); 
return true; 
} 
else 
return false; 
} 

That is called polymorphism… And strangely enough, it is also called overloading. 

Do not confuse this with overriding, which replaces a function or method with a new one, or rather, hides the old method and replaces it with a new one.
 

Answered By 75 points N/A #91794

What is the difference between function polymorphism and overloading?

qa-featured

Hi Josella,

They are more like the same, but the difference comes in when the actual method to execute is to be determined:

For instance:

record=newRecord()

record=newRecord(1000)

The compiler will tell which constructor  to use just by the method signature, the number and types of parameters too. The method to be  used for execution is determined by early binding.

Access the following link to read more:

Visit to Read more.

Hope this helps.
 
Regards,
Lee Hung.

Related Questions