Why can't static methods be abstract in Java?

后端 未结 25 2866
不思量自难忘°
不思量自难忘° 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 08:45

    Because abstract class is an OOPS concept and static members are not the part of OOPS....
    Now the thing is we can declare static complete methods in interface and we can execute interface by declaring main method inside an interface

    interface Demo 
    {
      public static void main(String [] args) {
         System.out.println("I am from interface");
      }
    }
    

提交回复
热议问题