Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't you have a static and non-static method with the same method signature in Java?

Tags:

java

Doesn't really seem to make sense to me. Maybe someone can help me understand. It seems kind of silly that I have to switch around the order of my parameters to have this feature.

like image 967
CodeCamper Avatar asked Dec 04 '22 03:12

CodeCamper


1 Answers

Because Java allows to invoke a static method in a non-static manner, i.e. on an object of the class. So, if a class has static and non-static methods - method() of same signature, an invocation like this: obj.method() would be ambiguous.

like image 172
Rohit Jain Avatar answered Jan 07 '23 13:01

Rohit Jain