Why can't you create static methods in an abstract class?

Asked 1 years ago, Updated 1 years ago, 84 views

abstract class foo {
    abstract void bar(); // <-- Pig 
    abstract static void bar2(); //<-- No
}

Why can't you define a static method for an abstract class like above?

java abstract-class static-methods

2022-09-21 22:12

1 Answers

The rule of 'abstract' is no implementation of the method.

The abstract class itself cannot be objectified, so implementation is not necessary.

In the static method, a function can be called without the class being objectified, but grammatically, an error is bound to occur.


2022-09-21 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.