-2

It is legal to have static block inside a class but illegal to have inside an interface. Please explain the reason.

1 Answers1

-3

You can have static initialisation, but you cannot have a static block. The fact the static initialisation needs a static code block to implement does change the Java syntax.

The point is you are not meant to have code in an interface (before Java 8) but you are allowed to initialise fields.

.......

static initialization in interface

reza ganji
  • 11
  • 2