• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Overloading method question

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think first one...
 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic