Why are class static methods inherited but not interface static methods?

Here’s my guess.

Since Cat can only extend one class if Cat extends Animal then Cat.identify has only one meaning. Cat can implement multiple interfaces each of which can have a static implementation. Therefore, the compiler would not know which one to choose?

However, as pointed out by the author,

Java already has this problem, with default methods. If two interfaces
declare default void identify(), which one is used? It’s a compile
error, and you have to implement an overriding method (which could
just be Animal.super.identify()). So Java already resolves this
problem for default methods – why not for static methods?

If I was to guess again, I’d say that with default the implementation is part of Cat‘s vtable. With static it cannot be. The main function must bind to something. At compile time Cat.identify could be replaced with Animal.identify by the compiler but the code wouldn’t match reality if Cat was recompiled but not the class that contains main.

Leave a Comment