Need of Method Overloading

What is the need of method overloading? What would happen if this feature is not present in Java?

Questions by shanky_06   answers by shanky_06

Showing Answers 1 - 6 of 6 Answers

yogesh249

  • Jan 30th, 2010
 

It is simple. 

Overloading is required, if you want a particular method to change its behavior based on the parameters passed.

Suppose you have a sum function

Sum(int i, int j)

This will add two integers, now if the requirement is that it should add 2 floats as well...then you need to overload it..

Sum(float i, float j)

msrmsr

  • Oct 4th, 2010
 

In Java one of the main concept is polymorphism
poly means many..taking many form with existing one.
if we use a method callled add();

add(int x,int y) we can  add 2 integers

add(float x,float y)we can add 2 float numbers

add(double x,double y) we can add 2 double numbers

with one add() method we are doing multiple works.so here polymorphism comes into picture.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions