Why can't static methods be abstract in Java?

后端 未结 25 2649
不思量自难忘°
不思量自难忘° 2020-11-22 08:34

The question is in Java why can\'t I define an abstract static method? for example

abstract class foo {
    abstract void bar( ); // <-- this is ok
    ab         


        
25条回答
  •  时光取名叫无心
    2020-11-22 09:02

    First, a key point about abstract classes - An abstract class cannot be instantiated (see wiki). So, you can't create any instance of an abstract class.

    Now, the way java deals with static methods is by sharing the method with all the instances of that class.

    So, If you can't instantiate a class, that class can't have abstract static methods since an abstract method begs to be extended.

    Boom.

提交回复
热议问题