Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading method question

 
Shanel Jacob
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void methodOverload (int var1, int var2, float var3)
{
m1 = var1; m2 = var2; m3 = var3;
}

** Choose ONE only. Which one overload methodOverload()?

 
Rahul Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think first one...
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ivan Rebrov:
Both methods are legal overloads of method in the task.

But the first method produces recurcive call of itself. So it leads to stack overflow error.

That's why I think, it is better to take the second method

[ August 11, 2006: Message edited by: Ivan Rebrov ]

[ August 11, 2006: Message edited by: Ivan Rebrov ]


Dear Ivan Rebrov,
Well I must clear you here, as you said that

first method produces recurcive call of itself. So it leads to stack overflow error.


Why do you think so, that first method produces recursive call to itself.

I am not looking any reason for that.

But yes both of them cann't be in same Class, because that might create a confusion for compiler to decide to call which method.

I hope I make it clear.
 
Ivan Rebrov
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ankur Sharma:
Why do you think so, that first method produces recursive call to itself.


Thank you, I was absolutely wrong. I didn't mention the change of order of arguments in inner method call.

So, the answer is "the first method"!

The second method's declaration is legal, but there is strange this() call, which is legal only in costructurs.
[ August 11, 2006: Message edited by: Ivan Rebrov ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic