can you declare an interface method static in java?

No, we cannot declare interface methods as static because static methods can not be overridden. Example

interface Test1 {
    static void show();
}
 
public class Main 
{ 
    void show(){
        System.out.println("Implmented method.");
    }
 
    public static void main(String[] args) 
    { 
        Main object = new Main();
        object.show();
    } 
}

Output

Main.java:2: error: missing method body, or declare abstract
    static void show();
                ^
1 error
Please follow and like us:
Content Protection by DMCA.com