| Author |
About overloading
|
Supriya Nimakuri
Ranch Hand
Joined: May 23, 2006
Posts: 83
|
|
public void area(int a, int b, float c){ p = a; q = b; r = c; } } Question 1: which of the following methods overloads the above method and how?? Question 2: for a mehtod to overload the argument list should be differenet. So, is the method overloaded if the aregument list changes its order public void setVar(int a, float c, int b) { area(a, b, c); } public void area(int a, float c, int b) { this(a, b, c); }
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
The signature is a combination of the name and parameter list. The order and type of the parameters are part of the signature. The first method changes the name so it is not overloading area. The second method does.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
These are overloaded: These are not overloaded (can you see why?):
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Supriya Nimakuri
Ranch Hand
Joined: May 23, 2006
Posts: 83
|
|
Hi Keithh... Can u tell me the answer with these 2 options..i have mistyped earlier..the method name is area in both the options...sorry abt that public void area(int a, float c, int b) { setVar(a, b, c); } public void area(int a, float c, int b) { this(a, b, c); }
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
This last one will not compile - two duplicate method signatures. Also this(a, b, c) is being misused - it's only used in a constructor. [ June 26, 2006: Message edited by: Barry Gaunt ]
|
 |
 |
|
|
subject: About overloading
|
|
|