As I found out, when overloading a Java method, we use the same name for all overloaded methods. And also their return type is not a question. But what happens if we use the same method as static and non-static, as in the example below? Can this method be considered overload?
class Adder {
static int add(int a, int b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
}
class Test {
public static void main(String[] args) {
Adder a1 = new Adder();
System.out.println(Adder.add(11, 11));
System.out.println(a1.add(11, 11, 51));
}
}
I read several articles, but they did not clarify my question.
source
share