Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSiddesh Gannu
3,565 PointsMethod overloading with same parameters in different order
I am curious that if I have 2 methods like:
public void name(String s, int a, double d){ }
public void name(double d, String s, int a) { }
Are these 2 methods legal? Is this allowed in Java? I'm mainly just curious. What if I wanted to write different code in each? would I need to then create 3 separate methods for this? Thanks! :)
1 Answer
Jeff Wilton
16,646 PointsYes, it is completely legal to have the same parameters in different order when overloading in Java.
Siddesh Gannu
3,565 PointsSiddesh Gannu
3,565 PointsThank you!
Ole Vølund Skov Mortensen
27,842 PointsOle Vølund Skov Mortensen
27,842 PointsAmazing. I see it as cascading method calls like CSS fx; so if I call 'Fill' with no arguments it'll act normal, if I add one argument it can seamlessly cascade to the method with that one argument handling. beautiful.