Interface Static Method in Java 8 or Above
Static Method in Interface
In earlier versions Java, before 1.8, it was not possible to create a static method in Interface, the only public abstract method was supported, but now from version 1.8, it is possible to declare static method also.
Let’s understand by example:
interface Message {
public abstract void msg ();
public default void msg2()
{
System.out.println(“Default method in Java”);
}
public static void msg3()
{
System.out.println(“Static method in Interface”);
}
}
public class Main implements Message {
public void msg ()
{
System.out.println(“This is Functional Interface Method”);
}
public static void main (String [] args)
{
Message m1 = new Main ();
m1.msg();
m1.msg2();
Message.msg3();
}
}