Why can't static methods be abstract in Java?

后端 未结 25 2246
不思量自难忘°
不思量自难忘° 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

    An abstract class cannot have a static method because abstraction is done to achieve DYNAMIC BINDING while static methods are statically binded to their functionality.A static method means behavior not dependent on an instance variable, so no instance/object is required.Just the class.Static methods belongs to class and not object. They are stored in a memory area known as PERMGEN from where it is shared with every object. Methods in abstract class are dynamically binded to their functionality.

提交回复
热议问题