• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About overloading

 
Supriya Nimakuri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are overloaded:

These are not overloaded (can you see why?):
 
Supriya Nimakuri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic