Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

method overloading

Former Member
0 Likes
472

how can the phenomenon of method overloading achieved through optional,can any one explain in brief

3 REPLIES 3
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
452

Hi,

In method overloading what we do is We want to pass different INPUT's in each method.

SO what you do is Your create one method with IMPORT paramters that are most likely to be used.

Then you add more IMPORT paramters that will be used when you want to say process different type of data then make these paramters optional.

So in the method if the OPTIONAL paramters are passed process the optional parameters also else just process for the mandatory paramters.

Check if the OPTIONAL paramters is supplied using the key word SUPPLIED.

Do reward usful answers.

Regards,

Sesh

Read only

Former Member
0 Likes
452

hi sandeep

Method Overloading

Method overloading is the ability to define several methods all with the same name. At first sight, that sounds stupid, but there are good reasons to want to. For example you are happy with the idea that ; that it is easy to treat a real number as a complex number. Suppose we wish to do so in our Complex class. It would seem natural to write a new add() method as follows:

Complex add(double x) {

return new Complex(this.x + x, y);

}

This is described by saying that the add() method has been overloaded. Although the name and return type are the same as the one used with a Complex argument, the arguments consist of different types and the JAVA compiler has no problem choosing the right one. We refer this combination of the number and types of arguments of a method as its signature. The combination of name and signature should be unique. Another example is the PrintStream class; you've seen that the print() and println() methods can take many different arguments.

Although you can overload methods, you can't overload operators: * and + can't be extended to work with matrices as they can in some other languages3.3. You have already seen the single exception to this: the + operator has been overloaded within JAVA for String concatenation.

Read only

Former Member
0 Likes
452

Hi Sandeep,

Simply we can call as "same name with different Parameters".

For example, You have method called add(). In method overloading you can use the same mehod add() as

add(int a, int b) - Here add()method uses two parameters ie. int,int

add(int, float,float) - Here add() method uses three parameters ie.int,float,float.

Regards

shri