JAVA Overloaded methods question?
I thought one and two were valid, and that three wasn't because three two same methods that do not accept parameters
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.
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.
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
I need to be more detail oriented :/
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 :)
You're welcome - glad it helped.
Join our real-time social learning platform and learn together with your friends!