Why can't static methods be abstract in Java?

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

    I also asked the same question , here is why

    Since Abstract class says, it will not give implementation and allow subclass to give it

    so Subclass has to override the methods of Superclass ,

    RULE NO 1 - A static method cannot be overridden

    Because static members and methods are compile time elements , that is why Overloading(Compile time Polymorphism) of static methods are allowed rather then Overriding (Runtime Polymorphism)

    So , they cant be Abstract .

    There is no thing like abstract static <--- Not allowed in Java Universe

提交回复
热议问题