aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading method question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading method question" Watch "Overloading method question" New topic
Author

Overloading method question

Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
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

Joined: Aug 01, 2006
Posts: 16
i think first one...
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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.


The Best way to predict your future is to create it - Every great individual common man
Ivan Rebrov
Ranch Hand

Joined: Jul 09, 2006
Posts: 30
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 ]

SCJP 5.0 - 95%<br />Preparing for SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading method question