Example with Static Block and Method:
java
CopyEdit
interface MyInterface {
static {
System.out.println("Static block in interface");
}
static void display() {
System.out.println("Static method in interface");
}
}
public class Test implements MyInterface {
public static void main(String[] args) {
MyInterface.display(); // β
Works fine
}
}
Conclusion:
Interface cannot have a constructor.
Interface can have static and default methods.
Interface can have static blocks (executed when the interface is first accessed).
interface can not contain static block But, chatgpt given interface can have static block