Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (fanduekisses):

JAVA Overloaded methods question?

OpenStudy (fanduekisses):

OpenStudy (fanduekisses):

I thought one and two were valid, and that three wasn't because three two same methods that do not accept parameters

OpenStudy (woodrow73):

Within option 1, there are also 2 of the same methods that both take an int as a parameter - despite both of those methods returning different data type; java only distinguishes between overloaded methods by the parameters taken into the method. Thus the overloaded methods in option1 do not work; and for the same reason the overloaded methods in option3 do not work.

OpenStudy (woodrow73):

For example; ``` public void someMethod(int a, int b, int k) { } public double someMethod(int i, int q, int uu) { } ``` the above will not work because both take 3 ints in their parameters. ``` public void someMethod(int a, int b, int k) { } public void someMethod(int i, int q, int uu, int tt) { } public void someMethod(double qa) { } ``` the above methods are distinguishable, because one takes 3 ints, and the other takes four ints, and the other takes a double - the parameters are all distinguishable.

OpenStudy (fanduekisses):

oooooh God, thank you, I see what I did wrong, instead of looking at the data type, I looked at the variable names lol, so in this case the correct answer was Satement II only then

OpenStudy (fanduekisses):

I need to be more detail oriented :/

OpenStudy (fanduekisses):

Also, thank you for clarifying that the data type of the return value doesn't matter, as long as the parameters are different, methods can be overloaded :) I wasn't so sure about it to be honest :)

OpenStudy (woodrow73):

You're welcome - glad it helped.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!