I have one more point to prove why interface methods cannot be static:
interface MyInterface { static void myStaticMethod(); }
Now let two classes implement "MyInterface"
//first grade
class MyClass1 implements MyInterface { static void myStaticMethod(){
//second class
class MyClass2 implements MyInterface { static void myStaticMethod(){
Now I create an instance as shown below:
1- MyInterface myObj1 = new MyClass1 (); 2- myObj1.myStaticMethod ();
3- MyInterface myObj2 = new MyClass2 (); 4- myObj2.myStaticMethod ();
// here, in lines 2 and 4, the call is incorrect, since myStaticMethod should be called using the class name (since myStaticMethod is defined as static), as shown below:
MyInterface.myStaticMethod (); → But in this case, how to call different implementations of myStaticMethod () with classes MyClass1 and MyClass2.
Thus, it was proved that static is not possible in declaring an interface method.
In conclusion, it is clear that this will be the opposite of redefining functionality.
source share