(Method)Overloading
Condition
Same method name
Same number and type of parameter
Same return type
long add(int a, long b) {return a+b;}
long add(long a, long b) {return a+b;}
//same type of parameter : duplicated. error
long add(int a, long b) {return a+b;}
long add(long a, int b) {return a+b;}
add(3,3L);
add(3L,3);
//ambiguous error. not clear that call first or second.
add(3,3);
//different return type. error
int add(int a, int b) {return a+b;}
long add(long a, long b) {return a+b;}
overloading example : different parameter, same function => method name : verb. ex) add, println, round, random...
: println(int), println(char), println(...)
Last updated
Was this helpful?