Overloading in same class Java -


this question has answer here:

i trying understand overloading @ moment , bit confused. understand when calling same method, cannot have exact same arguments. instance method called 2 int variables , 2 different int variables. if use int , float, okay. know return type not matter, being public or private method. matter?

for instance, call public int name(int x) able call private int name(int x)?

am correct in assuming public double name(string x) cause overloading in class? public int name(int x, string y) valid? passing string argument int function? cause overloading or error?

edit: not believe question duplicate, main question difference between public , private, method or different , cause overloading. did not see addressed in other question.

from oracle tutorial:

overloaded methods differentiated number , type of arguments passed method.

...

you cannot declare more 1 method same name , same number , type of arguments, because compiler cannot tell them apart.

so no access modifier doesn't count. cannot have both public int name(int x) , private int name(int x).

am correct in assuming public double name(string x) cause overloading in class?

yes since has same name different parameter type.

also public int name(int x, string y) valid? passing string argument int function? cause overloading or error?

again, since has same method name different parameter types, overloaded method.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -