Java Tutorials

Java 8 static, default methods in Interfaces

    Java version 8 onwards , an Interface can have static and Default methods. Earlier Java versions, once an Interface is published it should not be modified. In the sense, methods should not be deleted ,new methods can not be added or even method parameters should not be modified. In java 8 also same, existing methods should be not altered, but can have new methods decorated with default or static keywords.

These default and static methods can provide implementation at the interface level inself. Earlier versions of Java (<=7), an interface cannot contain any implementation methods. Java 8 added new feature, interface can have implementation methods using default or static keywords prefixed to a method.

Default method Implementation

The Following interface IMove has one abstract method Move and one default method Speed(which has implementation). The default method prefixed with default keyword.
      		interface IMove
      		   void Move();

	    	default void speed() {
	    	    System.out.println("IMove speed  default");

Static method Implementation